Dlookup Access 2007

What is wrong with this? It keeps telling me that the dlookup is wrong.
If LabelModelNumber.Caption = "" Then ExhaustStack.Value = "" Else ExhaustStack.Value = DLookup("ExhaustStack", "WasherModules", "ModelNumber ='" & LabelModelNumber.Caption & "'")

Open in new window

LVL 2
joshldAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Try this:

If LabelModelNumber.Caption = "" Then ExhaustStack.Value = "" Else ExhaustStack.Value = DLookup("ExhaustStack", "WasherModules", "[ModelNumber] = " & Chr(34) & LabelModelNumber.Caption & Chr(34))

mx
0
joshldAuthor Commented:
it give me a run-time error: object required.

what is Chr(34)? is that "'"?
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Chr(34) is a double quote ... used for clarity in posting.

OK ... what exactly is  'LabelModelNumber.Caption'  ?

mx
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

joshldAuthor Commented:
labelmodelnumber.caption would be the label of a model number I have on the form. In this case the caption is "W3X5X8-304-NH-H". I want it to match the model number from the table.
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Well ... I don' think you can really refer to the label caption property.  You need to get that value in a text box instead.

Lets try this:
Dim sCap as String
sCap = Me.LabelModelNumber.Caption

If LabelModelNumber.Caption = "" Then
      ExhaustStack.Value = "" 

Else ExhaustStack.Value = DLookup("ExhaustStack", "WasherModules", "[ModelNumber] = " & Chr(34) & sCap  & Chr(34))

End If

mx


0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Sorry .. ignore " You need to get that value in a text box instead."  of the last post.

mx
0
Rey Obrero (Capricorn1)Commented:
you CAN use the caption of the label

see this



Catalog.mdb
0
joshldAuthor Commented:
I still get the same error with this code:
LabelModelNumber.Caption = "" Then ExhaustStack.Value = "" Else ExhaustStack.Value = DLookup("ExhaustStack", "WasherModules", "[ModelNumber] = " & Chr(34) & txtModelNumber.value & Chr(34))

Open in new window

0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
What happens if you try this hard coded as a test:

IF LabelModelNumber.Caption = "" Then
ExhaustStack.Value = ""

 Else ExhaustStack.Value = DLookup("ExhaustStack", "WasherModules", "[ModelNumber] = " & Chr(34) & "W3X5X8-304-NH-H" & Chr(34))

End If

mx
0
Rey Obrero (Capricorn1)Commented:


what is the error are you getting??  post the exact error here

do a compact and repair of your db.
from VBA window do
Debug>Compile
make sure that no error is raised


If LabelModelNumber.Caption = "" Then
ExhaustStack.Value = "" 
Else
ExhaustStack.Value = DLookup("ExhaustStack", "WasherModules", "[ModelNumber] = '" & LabelModelNumber.Caption & "'")

end if
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
joshldAuthor Commented:
This is the error code.
errorcode.bmp
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Did you try the hard coded test ?

Also, which line of code is this happening on exactly ?

mx
0
joshldAuthor Commented:
Sorry, I'm stupid when it comes following the names I created. I needed to put "txt" in front of ExhaustStack.value.

Thanks guys.
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
"Sorry, I'm stupid when it comes following the names I created. I needed to put "txt" in front of ExhaustStack.value."

you are welcome.

mx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.