B
Brenda
I have five forms in my database. The Selection Table Form has two buttons
for the user to activate the other four forms. I am able to get the first
button to work, which allows the user open a specific form listed in a combo
box.
The other section contains a Search Button. The user has to select one of
the four forms listed in a combo box. Then they fill in one to three text
boxes and/or one combo box (company, website, city, state) with their search
criteria to bring up their findings. All of the forms have the same name for
these four items.
I am trying to get the findings to appear as a query. When I hit the
search button, I get the following error message: Run-time error '2342', A
RunSQL action requires an argument consisting of an SQL statement. I have
not been able to figure out why my variables values are not being but in my
SQL statement. Please help!!!
Below is my code:
Private Sub cmdSearch_Click()
Dim strCompN As String
Dim strWeb As String
Dim strCity As String
Dim strState As String
Dim strSQL As String
Dim strTable As String
If Me.Sourcetable.Value >= 1 Then
'Filtering each text box for values
If Not IsNull(Me.txtCompName) Then
strCompN = strCompN & "([Company] like ""*" & Me.txtCompName &
"*"")"
End If
If Not IsNull(Me.txtWeb) Then
strWeb = strWeb & "([Web] like ""*" & Me.txtWeb & "*"")"
End If
If Not IsNull(Me.txtCity) Then
strCity = strCity & "([City] like ""*" & Me.txtCity & "*"")"
End If
If Not IsNull(Me.cboState) Then
strState = strState & "([State]= """ & Me.cboState & """) and"
End If
strTable = Me.Sourcetable.Value
strSQL = "SELECT strTable.[Company], strTable.[Web], strTable.[City],
strTable.[State] FROM strTable WHERE strCompN & strWeb & strCity & strState"
DoCmd.RunSQL strSQL
Else
'Check to see if choice is selected
IsNull (Me.Sourcetable) Or Me.Sourcetable = ""
MsgBox "Please select a source form", vbOKOnly, "Required Data"
Me.Sourcetable.SetFocus
End If
End Sub
for the user to activate the other four forms. I am able to get the first
button to work, which allows the user open a specific form listed in a combo
box.
The other section contains a Search Button. The user has to select one of
the four forms listed in a combo box. Then they fill in one to three text
boxes and/or one combo box (company, website, city, state) with their search
criteria to bring up their findings. All of the forms have the same name for
these four items.
I am trying to get the findings to appear as a query. When I hit the
search button, I get the following error message: Run-time error '2342', A
RunSQL action requires an argument consisting of an SQL statement. I have
not been able to figure out why my variables values are not being but in my
SQL statement. Please help!!!
Below is my code:
Private Sub cmdSearch_Click()
Dim strCompN As String
Dim strWeb As String
Dim strCity As String
Dim strState As String
Dim strSQL As String
Dim strTable As String
If Me.Sourcetable.Value >= 1 Then
'Filtering each text box for values
If Not IsNull(Me.txtCompName) Then
strCompN = strCompN & "([Company] like ""*" & Me.txtCompName &
"*"")"
End If
If Not IsNull(Me.txtWeb) Then
strWeb = strWeb & "([Web] like ""*" & Me.txtWeb & "*"")"
End If
If Not IsNull(Me.txtCity) Then
strCity = strCity & "([City] like ""*" & Me.txtCity & "*"")"
End If
If Not IsNull(Me.cboState) Then
strState = strState & "([State]= """ & Me.cboState & """) and"
End If
strTable = Me.Sourcetable.Value
strSQL = "SELECT strTable.[Company], strTable.[Web], strTable.[City],
strTable.[State] FROM strTable WHERE strCompN & strWeb & strCity & strState"
DoCmd.RunSQL strSQL
Else
'Check to see if choice is selected
IsNull (Me.Sourcetable) Or Me.Sourcetable = ""
MsgBox "Please select a source form", vbOKOnly, "Required Data"
Me.Sourcetable.SetFocus
End If
End Sub