Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can an IF-Then in VB evaluate a Query Result?

Status
Not open for further replies.

dmon000

Technical User
Sep 9, 2003
79
US
I am trying to construct an on click event procedure for a command button that has an If statement. The "logic" is as follows:

cmd button opens form, form is based on parameter query prompting for ID number.

If Query returns record, Form1 opens.
If ID number does not exist in table, query returns no record, then open Form2.

How can one say "If query returns no record" or "If Form is Empty" in VB?

Or am I barking up the wrong tree.

Thanks!!
 
Code:
If Nz(DLookup("ID_Field","MyQuery","ID=" & txtID),0) <> 0 Then
   DoCmd.OpenForm "Form1"
Else
   DoCmd.OpenForm "Form2"
End if

I'm making an assumption that the ID field is a number, not text.

 
Are you using Form1 for updates and Form2 for new records?

If so, why not set a Boolean value to determine what SQL string to run when the "Save" button is clicked and just use the one form.

If not, disregard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top