Thank you in advance.
I have been searching the forum with no answers. Here is the situation.
I am running a query based on 4 different criteria on my form entered by the user (Company Name, Business Title, First Name and/or Last Name).
The user can choose any of the four criteria to run the search. I am not sure if my code is correct for any of this.
When I try to run the report it still asks for parameters How do I pass the parameters to the report.
Private Sub cmdfind_Click()
Dim smsgbox As String
Dim QryFileSt As String
Dim QryJoin As String
Dim QrySt As String
Dim stDocName As String
If chkcompname And IsNull(txtcompname) Then
smsgbox = " You have chosen to restrict by company but " & _
"have not selected a company name. Either select a company or " & _
"uncheck the ""Company Name"" checkbox."
MsgBox smsgbox, vbOKOnly, "Company Name Error"
End If
If txtcompname = Null Then
GoTo Line1:
End If
If txtcompname = Not Null Then
QrySt = "txtcompname"
QryJoin = QrySt
QryFileSt = QryJoin
End If
Line1:
If chkbustitle And IsNull(cbobustitle) Then
smsgbox = " You have chosen to restrict by Business Title but " & _
"have not selected a Business Title. Either select a Business Title or " & _
"uncheck the ""Business Title"" checkbox."
MsgBox smsgbox, vbOKOnly, "Business Title Error"
End If
If cbobustitle = Null Then
GoTo Line2:
End If
If cbobustitle = Not Null Then
QrySt = "cbobustitle"
If QryJoin = Null Then
QryJoin = QrySt
QryFileSt = QryJoin
End If
If QryJoin = Not Null Then
QryJoin = QryFileSt & " " & QrySt
QryFileSt = QryJoin
End If
End If
Line2:
If chkfirstname And IsNull(txtFirstName) Then
smsgbox = " You have chosen to restrict by First Name but " & _
"have not selected a First Name. Either select a First Name or " & _
"uncheck the ""First Name"" checkbox."
MsgBox smsgbox, vbOKOnly, "First Name Error"
End If
If txtFirstName = Null Then
GoTo Line3:
End If
If txtFirstName = Not Null Then
QrySt = txtFirstName
If QryJoin = Null Then
QryJoin = QrySt
QryFileSt = QryJoin
End If
If QryJoin = Not Null Then
QryJoin = QryFileSt & " " & QrySt
QryFileSt = QryJoin
End If
End If
Line3:
If chklastname And IsNull(txtLastName) Then
smsgbox = " You have chosen to restrict by Last Name but " & _
"have not selected a Last Name. Either select a Last Name or " & _
"uncheck the ""Last Name"" checkbox."
MsgBox smsgbox, vbOKOnly, "Last Name Error"
End If
If txtLastName = Null Then
End If
If txtLastName = Not Null Then
QrySt = "txtlastname"
If QryJoin = Null Then
QryJoin = QrySt
QryFileSt = QryJoin
End If
If QryJoin = Not Null Then
QryJoin = QryFileSt & " " & QrySt
QryFileSt = QryJoin
End If
End If
'then
'SELECT * FROM Customers2;
'WHERE (((Customers2!CompanyName) = [Forms]![txtcompname]) And ((Customers2![First Name]) = [Forms]![txtFirstName]) And ((Customers2![Last Name]) = [Forms]![txtLastName]) And ((Customers2![Business Title]) = [Forms]![cbobustitle]))
End Sub
I have been searching the forum with no answers. Here is the situation.
I am running a query based on 4 different criteria on my form entered by the user (Company Name, Business Title, First Name and/or Last Name).
The user can choose any of the four criteria to run the search. I am not sure if my code is correct for any of this.
When I try to run the report it still asks for parameters How do I pass the parameters to the report.
Private Sub cmdfind_Click()
Dim smsgbox As String
Dim QryFileSt As String
Dim QryJoin As String
Dim QrySt As String
Dim stDocName As String
If chkcompname And IsNull(txtcompname) Then
smsgbox = " You have chosen to restrict by company but " & _
"have not selected a company name. Either select a company or " & _
"uncheck the ""Company Name"" checkbox."
MsgBox smsgbox, vbOKOnly, "Company Name Error"
End If
If txtcompname = Null Then
GoTo Line1:
End If
If txtcompname = Not Null Then
QrySt = "txtcompname"
QryJoin = QrySt
QryFileSt = QryJoin
End If
Line1:
If chkbustitle And IsNull(cbobustitle) Then
smsgbox = " You have chosen to restrict by Business Title but " & _
"have not selected a Business Title. Either select a Business Title or " & _
"uncheck the ""Business Title"" checkbox."
MsgBox smsgbox, vbOKOnly, "Business Title Error"
End If
If cbobustitle = Null Then
GoTo Line2:
End If
If cbobustitle = Not Null Then
QrySt = "cbobustitle"
If QryJoin = Null Then
QryJoin = QrySt
QryFileSt = QryJoin
End If
If QryJoin = Not Null Then
QryJoin = QryFileSt & " " & QrySt
QryFileSt = QryJoin
End If
End If
Line2:
If chkfirstname And IsNull(txtFirstName) Then
smsgbox = " You have chosen to restrict by First Name but " & _
"have not selected a First Name. Either select a First Name or " & _
"uncheck the ""First Name"" checkbox."
MsgBox smsgbox, vbOKOnly, "First Name Error"
End If
If txtFirstName = Null Then
GoTo Line3:
End If
If txtFirstName = Not Null Then
QrySt = txtFirstName
If QryJoin = Null Then
QryJoin = QrySt
QryFileSt = QryJoin
End If
If QryJoin = Not Null Then
QryJoin = QryFileSt & " " & QrySt
QryFileSt = QryJoin
End If
End If
Line3:
If chklastname And IsNull(txtLastName) Then
smsgbox = " You have chosen to restrict by Last Name but " & _
"have not selected a Last Name. Either select a Last Name or " & _
"uncheck the ""Last Name"" checkbox."
MsgBox smsgbox, vbOKOnly, "Last Name Error"
End If
If txtLastName = Null Then
End If
If txtLastName = Not Null Then
QrySt = "txtlastname"
If QryJoin = Null Then
QryJoin = QrySt
QryFileSt = QryJoin
End If
If QryJoin = Not Null Then
QryJoin = QryFileSt & " " & QrySt
QryFileSt = QryJoin
End If
End If
'then
'SELECT * FROM Customers2;
'WHERE (((Customers2!CompanyName) = [Forms]![txtcompname]) And ((Customers2![First Name]) = [Forms]![txtFirstName]) And ((Customers2![Last Name]) = [Forms]![txtLastName]) And ((Customers2![Business Title]) = [Forms]![cbobustitle]))
End Sub