Link to home
Start Free TrialLog in
Avatar of joshld
joshld

asked on

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

Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Try this:

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

mx
Avatar of joshld
joshld

ASKER

it give me a run-time error: object required.

what is Chr(34)? is that "'"?
Chr(34) is a double quote ... used for clarity in posting.

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

mx
Avatar of joshld

ASKER

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.
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


Sorry .. ignore " You need to get that value in a text box instead."  of the last post.

mx
you CAN use the caption of the label

see this



Catalog.mdb
Avatar of joshld

ASKER

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

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
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of joshld

ASKER

This is the error code.
errorcode.bmp
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of joshld

ASKER

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

Thanks guys.
"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