"Form1"
combobox "cboModel"
Row Source
combobox "cboContactName "
quick explanation: I have a table named tblCOntacts and in this table i have 3 fields "LastName" and "FirstName" and "Initial" becuase i have multiple employess that have the same last names and sometimes same first and last name. So I have a query titled "Query1" with 2 feilds in it titled:
"File AS" and "Contact Name". Each of these fields combines the first and last name into one field. one does it first name last name and the other last name first name.
and then on form1 i have two cmdbuttons "cmdApplyFilter " and "cmdRemoveFilte r"
I have tried two differant codes
Here is the 1st code:
Using this code i get a.) two small form popups asking for the model value and contactname value then it returns a blank report
Here is the seconf code I tried:
For this i get the following error:
Run Time Error '3075':
Syntax error (missing operator) in query expression ' AND [Model]='*620".
Any help please!!
combobox "cboModel"
Row Source
Code:
SELECT [tblModel].[ID], [tblModel].[Model] FROM tblModel ORDER BY [Model];
Code:
SELECT [Query1].[Contact Name] FROM Query1 ORDER BY [Contact Name];
"File AS" and "Contact Name". Each of these fields combines the first and last name into one field. one does it first name last name and the other last name first name.
and then on form1 i have two cmdbuttons "cmdApplyFilter " and "cmdRemoveFilte r"
I have tried two differant codes
Here is the 1st code:
Code:
Option Compare Database Option Explicit Private Sub cmdApplyFilter_Click() Dim strModel As String Dim strContactName As String Dim strFilter As String ' Check that the report is open DoCmd.OpenReport "rptContacts", acPreview, , strFilter ' Build criteria string for Office field If IsNull(Me.cboModel.Value) Then strModel = "Like '*'" Else strModel = "='" & Me.cboModel.Value & "'" End If ' Build criteria string for Department field If IsNull(Me.cboContactName.Value) Then strContactName = "Like '*'" Else strContactName = "='" & Me.cboContactName.Value & "'" End If ' Combine criteria strings into a WHERE clause for the filter strFilter = "[Model] " & strModel & " AND [ContactName] " & strContactName ' Apply the filter and switch it on With Reports![rptContacts] .Filter = strFilter .FilterOn = True End With End Sub Private Sub cmdRemoveFilter_Click() On Error Resume Next ' Switch the filter off Reports![rptContacts].FilterOn = False End Sub
Here is the seconf code I tried:
Code:
Private Sub cmdOpenReport_Click() Dim strModel As String Dim strContactName As String Dim strFilter As String strFilter = "1=1 " ' Build criteria string for Office field If Not IsNull(Me.cboModel) Then strFilter = " AND [Model] ='" & Me.cboModel.Value & "'" End If ' Build criteria string for Department field If Not IsNull(Me.cboContactName) Then strFilter = " AND [Contact Name] ='" & Me.cboContactName.Value & "'" End If ' Apply the filter and switch it on DoCmd.OpenReport "rptContacts", acPreview, , strFilter End Sub
Run Time Error '3075':
Syntax error (missing operator) in query expression ' AND [Model]='*620".
Any help please!!
Comment