I've got an access database that I am working on, but I have now ran into a problem where I can not figure out the correct VBA syntax to use. As a sidenote - I am using Access 2003. What I would like to do is find out the syntax to use to retrieve data from a query result.
I have a query, that when ran, searches a table that contains 4 columns. The query prompts the user to enter a number which would be found in column 1. It then searches for every match of that number that was entered, and only returns a result if there is an occurrence where column 4 is empty on the same row. The max number of occurrences where column 4 can be empty is 1. So to summarize, when I run the query, it either returns a blank record (with a 0 in the first 2 columns and last 2 columns blank) or it will return a record that matches the criteria.
What I would like to do is if no records are found, I need to go to the Time_IN form. If 1 result is found, I need to go to the Time_OUT form. Hopefully this is an easy solution and I have most of the code written, but I am unsure of the syntax to use and my IF statement fails every time, reverting to the else statement. Here is a copy of the current code I am using (The Me.MO_ID = Null was my attempt at retrieving the results from the query):
Code:
Option Compare Database
Private Sub Command3_Click()
On Error GoTo Err_Command3_Click
DoCmd.OpenQuery "Open MO Evaluation Query", acViewNormal, acEdit
If Me.MO_ID = Null Then
DoCmd.OpenForm "Time_IN_Form", acNormal, "", "", , acNormal
Else
MsgBox "You must log out out of your current MO first."
DoCmd.OpenForm "Time_OUT_Form", acNormal, "", "", , acNormal
DoCmd.GoToControl "Time_OUT"
End If
Exit_Command3_Click:
Exit Sub
Err_Command3_Click:
MsgBox Err.Description
Resume Exit_Command3_Click
End Sub