Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DLOOKUP command not working

Status
Not open for further replies.

mot98

MIS
Jan 25, 2002
647
CA
Hi All,

I am trying to use the DLOOKUP command in my VBA code.

Basically I want it to lookup my query and if there are no records to skip the rest of my code.

Here is what I am using:
Code:
If dlookup(1, "Get_All2") < 0 Then
Call Do_Nothing
End If
[\code]

But it is not working....my code is still being run.

I have double checked the table the query is pulling from, and there are no records.


mot98
[cheers]
"Is it friday yet?"
 
Is this in VB6? DLookup is an access only feature.

If this is access, I'm not sure you can use dlookup in that fashion.

You might try setting a variable to =

Dlookup(1, "Get_All2")

then have your if based on the value of the variable.

Hope this helps,

Alex

A wise man once said
"The only thing normal about database guys is their tables".
 
The format of the VBA DLookup function is:

Value = DLookup("Column name", "Table or Query Name", "Condition")

This can be equated to a SQL statement like:

SELECT [Column Name] FROM [Table or Query Name] WHERE Condition


So yours should look something like this:

Code:
If Nz(DLookup("ColName", "Get_All2", "OtherColName=1"), 0) = 0 Then
    Call Do_Nothing
End If

It's a good idea to use the Nz function to guard against DLookup returning a NULL value when the value is not found.




Bob Boffin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top