DLookup as ControlSource through VBA code

brunopg7

Registered User.
Local time
Today, 18:49
Joined
Apr 20, 2011
Messages
14
Below is my code:
Forms![OrderForm]![Sku].ControlSource =
"=DLookUp(""[Sku]"",""OrderTable"",
""ItemNumber = '" & Forms![OrderForm]![ItemNumber] & "')"
I run the above code and the control source is now:
=DLookUp("[Sku]","OrderTable",
"ItemNumber = '1234-BA')
How do I change my code so I see the below in my control source:
=DLookUp("[Sku]","OrderTable",
"ItemNumber = '" & Forms![OrderForm]![ItemNumber] & "')
 
it is the same thing i believe...when you run code it shows you the actual value from Forms![OrderForm]![ItemNumber] instead.

so if you changed the value to itemnumber to 2222-BA, and ran it, this would show up


Code:
=DLookUp("[Sku]","OrderTable",
"ItemNumber = '2222-BA')

is it not doing what it supposed to or are you just concerned with what its showing in the controlsource?
 
it is the same thing i believe...when you run code it shows you the actual value from Forms![OrderForm]![ItemNumber] instead.

so if you changed the value to itemnumber to 2222-BA, and ran it, this would show up


Code:
=DLookUp("[Sku]","OrderTable",
"ItemNumber = '2222-BA')
is it not doing what it supposed to or are you just concerned with what its showing in the controlsource?

The issue is that it is the control source for a field in a datasheet.
When I set the control source manually
Code:
=DLookUp("[Sku]","OrderTable",
"ItemNumber = '" & Forms![OrderForm]![ItemNumber] & "')
it works, but if I set it through VBA it doesn't do it on an itemNumber per ItemNumber basis.
 
check your quotation marks on

Code:
Forms![OrderForm]![Sku].ControlSource = 
"=DLookUp(""[Sku]"",""OrderTable"",
""ItemNumber = '" & Forms![OrderForm]![ItemNumber] & "')"

you've cancelled out all the quotations except for

Code:
'" & Forms![OrderForm]![ItemNumber] & "'

try cancelling them out and see if that works
 
Code:
Forms![OrderForm]![Sku].ControlSource = 
"=DLookUp(""[Sku]"",""OrderTable"",
""ItemNumber = """" & Forms![OrderForm]![ItemNumber] & """""")"

try this
 
Code:
Forms![OrderForm]![Sku].ControlSource = 
"=DLookUp(""[Sku]"",""OrderTable"",
""ItemNumber = """" & Forms![OrderForm]![ItemNumber] & """""")"
try this

Ok I tried your code and got this as the control source:
Code:
  =DLookUp("[Sku]","OrderTable",
"ItemNumber = "" & Forms![OrderForm]![ItemNumber] & """)
 
This worked!
Code:
"=DLookUp(""Sku"",""OrderTable"",""ItemNumber='"" & "Forms![OrderForm]![ItemNumber]" & ""'"")"
 
glad you got it working, those single and double quotation marks can be a pain sometimes lol
 

Users who are viewing this thread

Back
Top Bottom