I have a form that has search fields in the header and the results in the details section, I have the details section populated via a query that I have created that is ordered via “Issued Date”. However when I view the data it is not ordered by “Issued Date”, but ordered by “Account Number”
Is their any code I can add to my search or my criteria coding that could make this data be ordered by tblAccount.[Issued Date] ?
I have the following search code:-
Private Sub btnSearch_Click()
' Update the record source
Form_frmMain.RecordSource = "SELECT tblCustomer.[Customer Name], tblAccount.[Issued Date], tblCustomer.[Customer Ref], tblCustomer.[Street Number], tblCustomer.[Tot Bal O/S], tblAccount.[Account Number] FROM tblAccount INNER JOIN tblCustomer ON tblAccount.[Customer Reference]=tblCustomer.[Customer Ref]" & BuildFilter
Form_frmMain.Caption = "Your Search Results"
End Sub
Private Function BuildFilter() As Variant
Dim varWhere As Variant
Dim varColor As Variant
Dim varItem As Variant
Dim intIndex As Integer
varWhere = Null ' Main filter
' Check for LIKE Customer Name
If Me.txtcustname > "" Then
varWhere = varWhere & "[Customer Name] LIKE ""*" & Me.txtcustname & "*"" AND "
End If
' Check for LIKE Customer Reference
If Me.txtCustRef > "" Then
varWhere = varWhere & "[Customer Reference] LIKE ""*" & Me.txtCustRef & "*"" AND "
End If
' Check for LIKE Account Number
If Me.txtAccNum > "" Then
varWhere = varWhere & "[Account Number] LIKE ""*" & Me.txtAccNum & "*"" AND "
End If
' Check if there is a filter to return...
If IsNull(varWhere) Then
varWhere = ""
Else
varWhere = "WHERE " & varWhere
' strip off last "AND" in the filter
If Right(varWhere, 5) = " AND " Then
varWhere = Left(varWhere, Len(varWhere) - 5)
End If
End If
BuildFilter = varWhere
End Function
Is their any code I can add to my search or my criteria coding that could make this data be ordered by tblAccount.[Issued Date] ?
I have the following search code:-
Private Sub btnSearch_Click()
' Update the record source
Form_frmMain.RecordSource = "SELECT tblCustomer.[Customer Name], tblAccount.[Issued Date], tblCustomer.[Customer Ref], tblCustomer.[Street Number], tblCustomer.[Tot Bal O/S], tblAccount.[Account Number] FROM tblAccount INNER JOIN tblCustomer ON tblAccount.[Customer Reference]=tblCustomer.[Customer Ref]" & BuildFilter
Form_frmMain.Caption = "Your Search Results"
End Sub
Private Function BuildFilter() As Variant
Dim varWhere As Variant
Dim varColor As Variant
Dim varItem As Variant
Dim intIndex As Integer
varWhere = Null ' Main filter
' Check for LIKE Customer Name
If Me.txtcustname > "" Then
varWhere = varWhere & "[Customer Name] LIKE ""*" & Me.txtcustname & "*"" AND "
End If
' Check for LIKE Customer Reference
If Me.txtCustRef > "" Then
varWhere = varWhere & "[Customer Reference] LIKE ""*" & Me.txtCustRef & "*"" AND "
End If
' Check for LIKE Account Number
If Me.txtAccNum > "" Then
varWhere = varWhere & "[Account Number] LIKE ""*" & Me.txtAccNum & "*"" AND "
End If
' Check if there is a filter to return...
If IsNull(varWhere) Then
varWhere = ""
Else
varWhere = "WHERE " & varWhere
' strip off last "AND" in the filter
If Right(varWhere, 5) = " AND " Then
varWhere = Left(varWhere, Len(varWhere) - 5)
End If
End If
BuildFilter = varWhere
End Function