DLookup Headache

Gregc

Board Regular
Joined
Apr 24, 2002
Messages
75
I am using DLookup to fill in a form. If I enter a value in a como box that is not in the list, DLookup returns the same record from the table everytime. If I enter a value that is in the list it returns the correct information from the table. I can't figure out why it won't return a null value for a record that is not in the list. I think that is what it should do.

Here is a copy of one line:

!txtJobName = DLookup("[strJobName]", "tblJobInformation", "'[strJobNumber]='" & "'" & JobNumber & "'")

The JobNumber is text.

I am going nuts trying to figure this out. It was returning the same record everytime until I deleted that record from the table. But that is a question for some other time.

Thanks for the help.
Greg
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Looks like you have too many single quotes in your criteria. Since it is a text value you need single quotes around the test expression only (eg
"[strJobNumber] = '" & YourVariable & "'" which would resolve to
"[strJobNumber] = '1234'"). You do not need them around the variable name used in your test. Its late and I hope I read your code correctly

Hope this helps!
 
Upvote 0
Thanks for the help, that was the problem. I tried every variation but that one.

Thanks agian,

Greg
 
Upvote 0

Forum statistics

Threads
1,221,581
Messages
6,160,630
Members
451,661
Latest member
hamdan17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top