Using IIF to open a form?

  • Thread starter Thread starter JoeG via AccessMonster.com
  • Start date Start date
J

JoeG via AccessMonster.com

I have a query that looks for a customer number based on a card reader swipe -


IF the query returns a null, customer not found THEN, I want to open a "add
new customer" form, ELSE open "new transaction form".

Can the conditional IIF be used to open a form rather than return a message
or is something more complex needed?

Thanks
 
Sure. However, I would use a DLookup rather than a Query to get one record:

Docmd.Openform IIf(IsNull(DLookup("[CUST_NO]","tblCustomer","[CUST_NO] = '"
& <???> & "'"), "AddForm", "TransActionForm")

the <???> would be whereever the customer number you want to look for is.
Also, the above is "air code", so may not be syntactically correct, but this
should give you a good idea.

If you use a query, then you have to establish a recordset, test for number
of records, and destroy the recordset. More code, less efficient.
 
Back
Top