In a table where there are three fields for address: Street No, Address0, Address1, I build a "full address" with the following string in a query for the form:
On the form there are some sort options for the user, one of them being Street No. That works fine, but I also have filters on the same form based on Districts in a Regional Area. I build the sort with the following code and set the form Orderby property.
So if the user has selected a filter based on either district or area, I would like them to see the results in Datasheet form view grouped.
My problem is that when I sort on Street No, it is not grouping or sorting as I expect for example:
1 Seaside
10 Seaside
10 Fairgreen
11 Seaside
17 Seaside
17 Fairgreen
etc.
Whereas I would like to have the following
1 Seaside
10 Seaside
11 Seaside
17 Seaside
10 Fairgreen
17 Fairgreen
I wonder what I am doing wrong or if I have explained myself clearly?
I appreciate your expert advice and help as usual
Regards
John
Code:
FullAddress: IIf(Not IsNull([address1]),Trim([street no]) & " " & Trim([ADDRESS0]) & ", " & Trim([address1]),Trim([street no]) & " " & Trim([Address0]))
On the form there are some sort options for the user, one of them being Street No. That works fine, but I also have filters on the same form based on Districts in a Regional Area. I build the sort with the following code and set the form Orderby property.
Code:
If Me.Sort1 <> "" Or Me.Check1 <> "" Then
strsql = Buildsqlstring(Me.Sort1, Me.Check1)
'Build strSQL String to sort the data
Me.OrderBy = strsql
Me.OrderByOn = True
End If
Code:
Function Buildsqlstring(Sort1 As String, Optional Check1 As Boolean) As String
Dim strsql As String
'Build strSQL String to sort the data
If Sort1 <> "" Then
If Sort1 = "street no" Then
strsql = strsql & "[" & Sort1 & "]"
' strsql = strsql & "," & "[" & "address0" & "]" ' Add the field address0
' strsql = strsql & "," & "[" & "Address1" & "]" ' Add the field address1
Else: strsql = strsql & "[" & Sort1 & "]"
End If
If Not IsMissing(Check1) Then If Check1 = True Then strsql = strsql & " DESC"
strsql = strsql & ", "
End If
If strsql <> "" Then
'Strip Last Comma & Space
strsql = Left(strsql, (Len(strsql) - 2))
Buildsqlstring = strsql
End If
End Function
So if the user has selected a filter based on either district or area, I would like them to see the results in Datasheet form view grouped.
My problem is that when I sort on Street No, it is not grouping or sorting as I expect for example:
1 Seaside
10 Seaside
10 Fairgreen
11 Seaside
17 Seaside
17 Fairgreen
etc.
Whereas I would like to have the following
1 Seaside
10 Seaside
11 Seaside
17 Seaside
10 Fairgreen
17 Fairgreen
I wonder what I am doing wrong or if I have explained myself clearly?
I appreciate your expert advice and help as usual
Regards
John