I keep getting a run time error 2501 when I try to open a form to display the results of my search.
Here is my code..
I have been racking my brain any tips would be greatly appriciated!!
Code:
Option Compare Database 'Use database order for string comparisons
Private Sub cmdSearch_Click()
'Set the Dimensions of the Module
Dim strSQL As String, strOrder As String, strWhere As String
Dim dbNm As Database
Dim qryDef As QueryDef
Set dbNm = CurrentDb()
'Constant Select statement for the RowSource
strSQL = "SELECT tblDemographics.DG_ControlID " & _
"FROM tblDemographics"
strWhere = "WHERE"
strOrder = "ORDER BY tblDemographics.DG_ControlID;"
'Set the WHERE clause for the Listbox RowSource if information has been entered into a field on the form
If Not IsNull(Me.txtControlID) Then
strWhere = strWhere & " (tblDemographics.DG_ControlID) Like '*" & Me.txtControlID & "*' AND"
End If
'Remove the last AND from the SQL statment
strWhere = Mid(strWhere, 1, Len(strWhere) - 5)
'Pass the SQL to the RowSource of the listbox
Me.lstCustInfo.RowSource = strSQL & " " & strWhere & "" & strOrder
End Sub
Private Sub lstCustInfo_DblClick(Cancel As Integer)
'Open frmCustomer based on the ID from lstCustInfo listbox
DoCmd.OpenForm "frmDemographics", , , "[DG_ControlID] = " & Me.lstCustInfo, , acDialog
End Sub