Essentially I am trying to find if a user is currently logged in before making a new row with TimeIn, but with the code as it is written, a user can check in multiple times without checking out (TLog_TImeOut field is null). My code is listed below.
If Not IsNull(DLookup("[TLog_TimeIn]", "TIMELOG", "IsNull(TLog_TImeOut)= True And NetID = '[TempVars]![CurrentID]'")) Then
MsgBox ("Please Check out!")
DoCmd.Close acForm, "CHECKIN", acSaveNo
Exit Sub
Else
NetID = [TempVars]![CurrentID]
TLog_TimeIn = Now()
MsgBox ("Thanks for checking in!")
DoCmd.Close acForm, "CHECKIN", acSaveYes
Exit Sub
End If
Your
DLOOKUP
should be more like this:Specifically your condition -
Should be treated like the
WHERE
condition in a SQL statement.First, if possible, you want to avoid Access functions for speed reasons (not a big deal in this particular case) so using
Is Null
is better thanIsNull(XXX)=True
but especially this part:This is going to literally compare NetID to the string '[TempVar]![CurrentID]' so what you want is to build this string like this:
(Assuming [TempVars] is a hidden form that you use to save variable values) which if CurrentID is BOB on that form will yield:
Which is what you want.