PDA

View Full Version : Solved: easy DLookup but I keep getting Error 2001



Trevor
03-26-2008, 09:12 PM
I have a simple Dlookup (the example is all over the internet but I keep getting Error 2001 and can't seem to solve it, I have it placed on click of command button, it is the only action there with a textbox to display the
result... this should get the setting from the settingstbl, where the varsettingName = Save, and then display the setting in text1(textbox on form)

Text1 = DLookup("[Setting]", "SettingsTbl", "VarSettingName = Save")

Thanx for heping me solve my simple problem

OTWarrior
03-27-2008, 02:24 AM
me.Text1.text = DLookup("[Setting]", "SettingsTbl", "VarSettingName = Save")


does this fix it?

or (same thing, but useful if you need to use the value a second time)

dim txtValue as string
txtValue = DLookup("[Setting]", "SettingsTbl", "VarSettingName = Save")
me.text1.text = txtValue

DarkSprout
03-27-2008, 03:00 AM
Strings need to be in quotes
Try:

[Text1] = DLookup("[Setting]", "SettingsTbl", "[VarSettingName] = 'Save'")

Trevor
03-27-2008, 07:40 AM
It looks like(lookeing at what you guys are telling me) is that my criteria should had been individualy quoteted, OTWarrior, I tried that but I still got 2001error. Darksprout- I still have to try your post, wiil let you know, thanks again for helping

Trevor
03-27-2008, 10:59 AM
Now Im getting Invalid use of null error and I am using

Dim text as string
Text = DLookup("Setting", "SettingsTbl", "VarSettingName" = "Save")
Me.[Text1] = Text

I have even checked my table and column name , and , they are spelled correctly and the fields do contain values

Trevor
03-27-2008, 11:01 AM
I could always open a rst and loop through it for the value I want, but I would like to avoid that if possable

akn112
03-27-2008, 11:18 AM
Trevor, you can't just take the equal sign out of the criteria quotations. It should look like "[field] = 'criteria' " where your string value is surrounded in single quotes. Think of single quotes as quotes inside quotes.

Darksprouts posting is the only way to do it.

If you want to fill it with a variable string, it must take the following structure

"[field] = ' " & myvariable & " ' "

Trevor
03-27-2008, 12:07 PM
OHHH,
I didn't notice his single quotes before, I only saw the double quotes, Damn it sucks beeing 1/2 blind at times, thank, will try and let you know

Trevor
03-27-2008, 12:23 PM
Ok, AKN and darksprout, you were right, thanx