DLookup syntax error? (1 Viewer)

mlopes1

Registered User.
Local time
Today, 05:17
Joined
Sep 4, 2002
Messages
76
Dim fmName as string
Dim InUseVar as string

fmName = "Test1"

InUseVar = DLookup("[In_Use]", "All_Forms", "[Form_Name] = ' " & fmName & " ' ")

Basically, I just want to take the value of the field In_Use found in table All_Forms and set InUseVar equal to it, when the field Form_Name = fmName.

I get the error :previous operation was canceled.

Any clues here? Hopefully this enough info,

Marco
 

Mile-O

Back once again...
Local time
Today, 09:17
Joined
Dec 10, 2002
Messages
11,316
You are looking for a text string with the value " Test1 " and not "Test1"

Note the spaces on either side of the value; you are putting these in. Wrong!

InUseVar = DLookup("[In_Use]", "All_Forms", "[Form_Name] = """ & fmName & """")
 

mlopes1

Registered User.
Local time
Today, 05:17
Joined
Sep 4, 2002
Messages
76
Hi Pat,

Thanks for that syntax fix, I would have never found it. I entered it exactly as you suggested however still was told "Previous Operation Canceled". Perhaps you have some ideas why this is happening.

I call the function out of an OnClick event...

fmName = "test1"

FmCheck fmName

And then in the function have your code:

Dim InUseVar as String

InUseVar = DLookup("[In_Use]", "All_Forms", "[Form_Name] = ' " & fmName & " ' ")


Anything jump out at you here? Thanks as always for all your help. Much needed!

Marco
 

dcx693

Registered User.
Local time
Today, 04:17
Joined
Apr 30, 2003
Messages
3,265
Pat? I didn't see a Pat in this thread - (in about 20,000 other threads yes, but not this one. :D )
 

mlopes1

Registered User.
Local time
Today, 05:17
Joined
Sep 4, 2002
Messages
76
LOL.... sorry about that. I guess its just like 2nd nature now to write that. Thanks for your answer!
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 04:17
Joined
Feb 19, 2002
Messages
43,676
Mile's new avitar does look a little like me :)
 

mary.h

Registered User.
Local time
Today, 09:17
Joined
Aug 21, 2003
Messages
48
Hi Marco,

well, I've got sometimes problems with DLookup, if it the search-string isn't found and so DLookup returns "NULL". So I use

myString = Nz(DLookup("FieldName","Tablename","Field2='" & var & "'"),"empty")

So myString = "empty", if DLookup is Null.

Maybe that helps.

Regards,
Mary H.
 

Users who are viewing this thread

Top Bottom