Re: Create a multiple parameter search form for a query



On your Prompts form, you should have a [Submit] button that will have
an On-click event to hold some VBA code.

Dim qd As DAO.QueryDef
Dim Whereclause As String
Dim ssql As String
Dim Assignment As Integer

ssql = "SELECT * From table"

IF me!AccountNumber Not NULL Then
Whereclause = " WHERE AccountNumber = " & Me!AccountNumber
End If

IF CustomerAgent Not NULL then
IF Whereclause is NULL Then
whereclause = " WHERE CustomerAgent = " & me!CustomerAgent
Else
Whereclause = " AND CustomerAgent = " & me!CustomerAgent
End IF
END IF

' Make IF statements for each field on the Prompts form.
' At the end you will have a Whereclause that has entries for those
fields that were filled in; or possibly Whereclause will be NULL.

IF Whereclause Not NULL then
ssql = ssql & Whereclause
End IF

'Then execute the ssql or save it as a query and then do whatever other
VBA code you want.

.


Quantcast