This problem is driving me crazy.
Hello there,
i am trying to create a search form for records in my access database. The search form will contain text boxes and a multi select list box. The user can enter their search criteria eg. surname, reg num, etc. in the text boxes. The multi select list box allows the user to select multiple counties which they have the option of including in the search. The user should be able to select or omit the criteria as they desire.
I have messed around with the code for the last days but i am unable to intergrate the user selected criteria from a multi select list box.
I have been able to fix to the basics like first name and surname search but i cant manage the user selection from the multi select list box of counties.
This in my attempt it's bad i know.
Listbox info
The list box is a selection of counties its called list0 its a look up values in my counties table.
Name = List0
Row Source = SELECT [tblCounties].[CountyCode], [tblCounties].[County] FROM tblCounties;
Multi select = simple
I really like the subform the results are displayed in do you think i can make it open in a report format also?
Below is my code minus the failed list box intergration attempt to avoid confusion.
Many thaks once again all the way from Ireland. Kind regards
James
Hello there,
i am trying to create a search form for records in my access database. The search form will contain text boxes and a multi select list box. The user can enter their search criteria eg. surname, reg num, etc. in the text boxes. The multi select list box allows the user to select multiple counties which they have the option of including in the search. The user should be able to select or omit the criteria as they desire.
I have messed around with the code for the last days but i am unable to intergrate the user selected criteria from a multi select list box.
I have been able to fix to the basics like first name and surname search but i cant manage the user selection from the multi select list box of counties.
This in my attempt it's bad i know.
Code:
If Len(Me.List0 & vbNullString) Then For Each Itm In ctl.ItemsSelected strSQLWhere = "WHERE [county] Chr(34) & ctl.ItemData(Itm) & Chr(34) Else strSQLWhere = "WHERE [county] = " & Chr$(39) & Me.List0 & Chr$(39) End If strSQLWhere = strSQLWhere & strJoin End If
The list box is a selection of counties its called list0 its a look up values in my counties table.
Name = List0
Row Source = SELECT [tblCounties].[CountyCode], [tblCounties].[County] FROM tblCounties;
Multi select = simple
I really like the subform the results are displayed in do you think i can make it open in a report format also?
Below is my code minus the failed list box intergration attempt to avoid confusion.
Many thaks once again all the way from Ireland. Kind regards
James
Code:
Private Sub cmdPlease_Click() Dim strSQLHead As String Dim strSQLWhere As String Dim strSQLOrderBy As String Dim strSQL As String Dim strJoin As String strJoin = " AND " strSQLHead = "SELECT * FROM tblMemberDetails " If Len(Me.txtSurname & vbNullString) Then If (Me.chkLike) Then strSQLWhere = "WHERE [surname] Like " & Chr$(39) & "*" & Me.txtSurname & "*" & Chr$(39) Else strSQLWhere = "WHERE [surname] = " & Chr$(39) & Me.txtSurname & Chr$(39) End If strSQLWhere = strSQLWhere & strJoin End If If Len(Me.txtFirstName & vbNullString) Then If (Me.chkLike) Then strSQLWhere = "WHERE [FirstName] Like " & Chr$(39) & "*" & Me.txtFirstName & "*" & Chr$(39) Else strSQLWhere = "WHERE [FirstName] = " & Chr$(39) & Me.txtFirstName & Chr$(39) End If strSQLWhere = strSQLWhere & strJoin End If If Len(strSQLWhere) Then strSQLWhere = Left$(strSQLWhere, Len(strSQLWhere) - (Len(strJoin) - 1)) End If strSQLOrderBy = "ORDER BY " Select Case Me.fraOrderBy Case 1 strSQLOrderBy = strSQLOrderBy & "[surname]" Case 2 strSQLOrderBy = strSQLOrderBy & "[firstName]" Case 3 strSQLOrderBy = strSQLOrderBy & "[regNumber]" End Select strSQL = strSQLHead & strSQLWhere & strSQLOrderBy
Comment