RE: Concatenated Field - Sort Order



I just got done troubleshootingthe end query by putting the the [PrefSO] in
front of the phone type and found a quirk. I found that the sort order was
working in the subquery (when run by itself), but when put into the
concatenation string, this same data was not accurate. In other words if a
person had a phone type like 'pref' it was listing it as a 3 versus a 1. The
main query/concatenation doesn't seem to work well with 'Like' operators.

I ended up getting the accurate concatenated results by switching the
[PrefSO] to be the following: PrefSO:
IIf(Left([PhType],4)="Pref",1,IIf([PhType]="BB",2,3))

I don't know why this matters, but it does work. :)

"Vittles" wrote:

The concatenation coding is yours (as follows):
Function Concatenate2(pstrSQL As String, _
Optional pstrDelim As String = " / ") _
As String
'Created by Duane Hookom, 2003
'this code may be included in any application/mdb providing
' this statement is left intact

Dim rs As New ADODB.Recordset
rs.Open pstrSQL, CurrentProject.Connection, _
adOpenKeyset, adLockOptimistic
Dim strConcat As String 'build return string
With rs
If Not .EOF Then
.MoveFirst
Do While Not .EOF
strConcat = strConcat & _
.Fields(0) & pstrDelim
.MoveNext
Loop
End If
.Close
End With
Set rs = Nothing
If Len(strConcat) > 0 Then
strConcat = Left(strConcat, _
Len(strConcat) - Len(pstrDelim))
End If
Concatenate2 = strConcat
End Function

I add a number after the concatenate function name when I have modified the
joining string - for some purposes a comma is good, for others it isn't....
In the original it was a comma and in this version it is a "/".



"Duane Hookom" wrote:

Are you using Concatenate2 in both queries? Was Concatenate() modified to
Concatenate2()? I don't see where you are using "/" in this one.

You could also try to sort descending by:
PrefSO: Instr("~BB~Pref~",[PhType])
--
Duane Hookom
Microsoft Access MVP


"Vittles" wrote:

{Access2003}
I have a concatenated field in a main query set as follows:
Other Phone: Concatenate2("Select [PhType] & ': ' & [Phone#] FROM [Staff
Contact-OtherPhone SubQ] where [EmplNo]=" & [Employees].[EmplNo] & " ORDER BY
[PrefSO] ASC")

The SubQ [PrefSO] field (based directly off of a table) mentioned is set as
follows:
PrefSO: IIf([PhType] Like "Pref*",1,IIf([PhType]="BB",2,3))

When I pull up the sub query the sort order column is accurate, but when I
pull up the concatenated results from the main query the concatenated field
results are not being sorted by the PreSO field. I have a similar set up
(same concatenation module) in a different database and it works great (only
with a comma between the concatenated fields versus a / in this one) - what
am I missing?

.



Relevant Pages

  • Too Few Parameters Problem w/Query
    ... I am trying to run a concatenate function in a query and I'm having a ... Domain As String, _ ... ' Description: A generic "concatenation" routine. ... Dim strConcatenate As String ...
    (microsoft.public.access.gettingstarted)
  • Re: Too Few Parameters Problem w/Query
    ... when I run the query it grinds for about an hour and then says there ... Domain As String, _ ... ' Description: A generic "concatenation" routine. ... Dim strConcatenate As String ...
    (microsoft.public.access.gettingstarted)
  • Re: Aggregate string concatenation efficiency problem
    ... that involves a query and also involves a string that is being ... The string concatenation operation? ... data from Column5, the column in question, things slow way down. ... The string concatenation that I perform with the string builder ...
    (comp.databases.ms-access)
  • Re: Using Variables in an INSERT INTO query
    ... when you want to concatenation a string you use ... when you want to concatenation variables with a string you use ... I want to use the query to append a single row ... > Dim qdf As QueryDef ...
    (microsoft.public.access.queries)
  • RE: Concatenated Field - Sort Order
    ... The concatenation coding is yours: ... Function Concatenate2(pstrSQL As String, _ ... Dim strConcat As String 'build return string ... I have a concatenated field in a main query set as follows: ...
    (microsoft.public.access.queries)

Loading