Correct Syntax? (1 Viewer)

2wistd

Registered User.
Local time
Yesterday, 20:16
Joined
Jan 17, 2013
Messages
66
I am trying to open a report using this code:

DoCmd.OpenReport "rptCustom", acPreview, , "IIf(IsNull([Forms]![frmChooseFields]![chooseflight], ,[Flight] = [Forms]![frmChooseFields]![chooseflight])"

The form has a combobox with 4 different options for flights. When you select one and click the button, it will filter to show only those who are part of that flight. I want to be able to select 'none' and have it show all.

Something is wrong with my statement, but I can't figure it out.
 

plog

Banishment Pending
Local time
Yesterday, 22:16
Joined
May 11, 2011
Messages
11,665
It doesn't work that way--You're trying to apply two layers of logic into the criteria argument of DoCmd. The argument itself is criteria, but you are trying to use criteria in determining what that criteria should be.

You can accomplish what you want, but not like that. My suggestion is to create a string that will contain what you want the final criteria to be. Before the Do.Cmd statement, create a string variable that will hold the criteria string you want to use, then build it based on your logic:

Code:
strCriteria As String
strCriteria = ""

(insert logic for setting strCriteria)


DoCmd.OpenReport "rptCustom", acPreview, , strCriteria
 

Users who are viewing this thread

Top Bottom