Select Query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I run a query based on the criteria of any one or combination of 4
fields being met?
 
I want to display a simple report that lists invoices received. I use a form
where I can enter a range of dates, a vendor, an account number, and/or
contact name. I would like my query to return records satisfying any one of
these criteria (e.g., if I just type in a vendor name it returns all records
with that vendor) or any combination of the other fields (e.g., all records
with a vendor specified with invoices within the range of dates that share
the same account number), etc.
 
I would use code in the form to create a where clause for the
DoCmd.OpenReport method.
Dim strWhere as String
strWhere = "1 = 1 "
If Not IsNull(Me.txtStart) Then
strWhere = strWhere & " AND [InvoiceDate] >=#" & _
Me.txtStart & "# "
End If
If Not IsNull(Me.txtEnd) Then
strWhere = strWhere & " AND [InvoiceDate] <=#" & _
Me.txtEnd & "# "
End If
'etc
DoCmd.OpenReport "rptInvoices", acPreview, , strWhere
 
Back
Top