View Single Post
  #4  
Old May 24th, 2010, 08:40 PM posted to microsoft.public.access.queries
Marshall Barton
external usenet poster
 
Posts: 5,361
Default Descision based on a query

If the query does not return any records then the DLookup
will faill to find anything so the result will be Null
making the If statement fail. If someone is checking in,
there won't be a record yet, right? On this case you should
check for Null:
If IsNull(DLookup("Present", "qry_GetWork")) Then

Are you sure the Present field in its table is a Yes/No
field? If it is, double check the value of the field is
either 0 or -1 (eg. SQL Server uses 0 and +1 instead of
Access's 0 and -1).

If none of that helps, try my earlier suggestion skip the
the query and have DLookup go directly to the table.


poorboy13 via AccessMonster.com wrote:
I appreciate the response - However, I have tried every which way I can think
of to write it and I'm not coming up with a correct answer.

To Clarify;
In the query "qry_GetWork" I have specified the criteria for "ShiftDate =
Date()" and "EmpID = [Forms]![Begin]![Employee ID]". (This, by itself, works
fine.)

So as best I can tell the If statement in VBA should look like this:
If DLookup("Present", "qry_GetWork") -1 Then

Now I get the opposite problem everything is going through like the box is
checked. Even if it is not, and even if there are no records at all in the
query.

I did the "-1" because if I have not signed in yet then the query will not
return any records.
Is that wrong?


Marshall Barton wrote:
I'm hoping this should be easy - I just can't seem to find the answer. I'm
guessing my syntax is wrong but I can not figure it out.

[quoted text clipped - 41 lines]
answer.
Or maybe there is a completely different way I should attack it????


Opening a query's datasheet does not make the query's data
available to your VBA code.

In your case, I think you want to use the DLookup function.
How you would do that depends on what you have in the query,
probably something vaguely like:
If DLookup("Present", "Attendance", "EmpID=" & something _
& " And datefield= Date()") = 0 Then


--
Marsh
MVP [MS Access]