If Nz(DLookup(... Not Working

G

Gntlhnds

Here is my code, and it is not working the way I want it to:

f Nz(DLookup("bShow", "tShowDialogs", "sFormName='" & Startup & "' AND
sUserName='" & CurrentUser & "'"), False)= True Then
'/open you dialog form
DoCmd.OpenForm "Startup"

End If

If checkbox "bShow" is false, then this code should open form "Startup", and
if it true, then this code should do nothing (this code is reference in an
autoexec macro). Instead, regardless of the checkbox, this code does
nothing. If I change the code to:

If Nz(DLookup("bShow", "tShowDialogs"), False) = False Then
'/open you dialog form
DoCmd.OpenForm "Startup"

End If

Then it works. This takes away from it being able to adjust for the user,
though. So how do I make it work?
 
C

CyberDwarf

I assume you are looking up these values in a table called tShowDialogs? If
so, and your table is on SQL Server, then beware of True/False values!
False will always be Zero, but True will be non-Zero. Therefore, you should
test as follows:-

If Nz(SLookup(.....), 0) = 0 'Testing for False
Or
If Nz(SLookup(.....), 0) <> 0 'Testing for True

HTH
Steve
 
G

George Nicholson

Instead, regardless of the checkbox, this code does nothing.

Assuming that your checkbox is bound to bShow in tShowDialogs...

Then my guess is that Dlookup is unable to find a record where BOTH
(tShowDialogs.sFormname = Startup) *AND* (tShowDialogs.sUserName =
CurrentUser). OR, if it does find a matching record, tShowDialogs.bShow for
that record is something other than True.


HTH,
 
G

Gntlhnds

There is only one record in the table, and sFormName=Startup and
sUserName=Admin, but no matter what bShow is, nothing happens. If it is
false, the code is supposed to open form Startup. If it is true, then the
code is supposed to do nothing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top