I've got a problem that I can't seem to find out, and hopefully someone here can chime in and help.
I've got a query that searches to see if there is a previous record matching an employee number that is entered. If a record is returned from the query, I need the Time_OUT form to be opened. If no record is returned, I need the Time_IN form to be opened.
Is it possible to set the result from a field in the query as a variable to later be used in an if statement? That is my only thoughts to making this work. When it runs the query, if the Time_OUT is NOT null (or if no new records are found), this is when I need the if statement to execute.
Here is my current code that I am using, and I don't seem to have it correct as it reverts to the ELSE statement everytime and always fails the IF statement. I don't know what to call the field in the query for it to look at. Currently in the code listed below, it says Me.MO_ID in that location.
I've got a query that searches to see if there is a previous record matching an employee number that is entered. If a record is returned from the query, I need the Time_OUT form to be opened. If no record is returned, I need the Time_IN form to be opened.
Is it possible to set the result from a field in the query as a variable to later be used in an if statement? That is my only thoughts to making this work. When it runs the query, if the Time_OUT is NOT null (or if no new records are found), this is when I need the if statement to execute.
Here is my current code that I am using, and I don't seem to have it correct as it reverts to the ELSE statement everytime and always fails the IF statement. I don't know what to call the field in the query for it to look at. Currently in the code listed below, it says Me.MO_ID in that location.
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
Last edited: