using Form data in query

S

shank

I'm trying to run a query with the below statement as criteria.

I'm trying to get by with designing one report and having it open per the
form being used.

Problem: It insists on evaluating the form field that is not used. How do I
get around that?

I would like the query to run regardless of which form is used.

IIf(IsNull([Forms]![frmAllPO]![PONo]),[Forms]![frmTempReport]![PONo],[Forms]![frmAllPO]![PONo])

thanks
 
J

John Spencer

One way to do this is to write a custom VBA function that will check to
see which form is open and then grab the information from the form and
return the desired value.

Another way - if you are using this query as the source for a report -
is to pass a where string when your code opens the report.

Something like the following.

Dim strWhere as String

strWhere = "[Name of the field]=""" & [Forms]![frmTempReport]![PONo] & """"
Docmd.OpenReport "ReportName",,,strWhere
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top