DLookUp troubles (1 Viewer)

MICHELE

Registered User.
Local time
Today, 05:45
Joined
Jul 6, 2000
Messages
117
I am trying to view information from a query field on a form that is bound by another query so I am trying to use DLookUp.
The form with the field is F-MainEntry. The query that is not bound to the form is Q-PURCHEXPORT2 and the field is STEEL. My DLookUp looks like this and is not working

DLookUp("[STEEL]","[Q-PURCHEXPORT2]","[LSC]=Form![F-MainEntry].[LSC]")

I've tried it a few different ways with no luck. Any help would be greatly appreciated!
 

Fizzio

Chief Torturer
Local time
Today, 05:45
Joined
Feb 21, 2002
Messages
1,885
If LSC is an integer
DLookUp("[STEEL]","[Q-PURCHEXPORT2]","[LSC]= " & Forms!F-MainEntry!LSC)

or

If LSC is text
DLookUp("[STEEL]","[Q-PURCHEXPORT2]","[LSC]= '" & Forms!F-MainEntry!LSC & "'")
 

MICHELE

Registered User.
Local time
Today, 05:45
Joined
Jul 6, 2000
Messages
117
Thank you.
I actually copied what you wrote and pasted it and it still doesn't work. LSC is a text field.
Could it have something to do with my query? The field STEEL is actually made from an expression.
 

Fizzio

Chief Torturer
Local time
Today, 05:45
Joined
Feb 21, 2002
Messages
1,885
No that does not matter. Is the LSC in Forms!F-MainEntry!LSC the name of a control or field value.
You do not actually need the [] around the query name

DLookUp("[STEEL]","Q-PURCHEXPORT2","[LSC]= '" & Forms!F-MainEntry!LSC & "'")

You should, however avoid using operators in the names of your fields, query names etc. Use an underscore _ instead.
 

MICHELE

Registered User.
Local time
Today, 05:45
Joined
Jul 6, 2000
Messages
117
OK. I changed the name of my form and my query and used this expression and it still won't work. I get #Name?

DLookUp("[STEEL]","Q_PurchExport","[LSC]= '" & Forms!F_MainEntry!LSC & "'")

Any other suggestions??

I'm going home now and will try again Monday. Thank You!
 

Fizzio

Chief Torturer
Local time
Today, 05:45
Joined
Feb 21, 2002
Messages
1,885
Have you preceded it with an = sign?
Also is the name of the form control correct ie the LSC in Forms!F_MainEntry!LSC ?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:45
Joined
Feb 19, 2002
Messages
43,484
Fizzio left out the square brackets :) They are REQUIRED whenever your object name is non-standard. You will have a lot less trouble with VBA if you use only properly formed object names - Upper and lower case letters, numbers 0-9, and the underscore (_). Start all names with a letter and keep them under 30 characters.

If LSC is an integer
DLookUp("[STEEL]","[Q-PURCHEXPORT2]","[LSC]= " & Forms![F-MainEntry]!LSC)

or

If LSC is text
DLookUp("[STEEL]","[Q-PURCHEXPORT2]","[LSC]= '" & Forms![F-MainEntry]!LSC & "'")
 

MICHELE

Registered User.
Local time
Today, 05:45
Joined
Jul 6, 2000
Messages
117
Thank you so much, both of you! It works now. I have been working with Access a while, but I steel need to learn so much. I will try to remember correct naming standards. It's gotten me in trouble before. I wish I could change them all that I did in the huge db that I already have.

Thanks again!
This Forum has been a job saver, literally!!
 

Users who are viewing this thread

Top Bottom