Dlookup

jcaptchaos2

Well-known Member
Joined
Sep 24, 2002
Messages
1,032
Office Version
  1. 365
Platform
  1. Windows
Hello,

Code:
ItemNumber = DLookup("[itemnumber]", "[shoporderstatus]", "[shopordernumber]= " & [Forms]![shop_floor_data_entry]![shopordernumber])

I need help with the Dlookup function, here is my formula, I can't seem to get it to work but in the past have been able to get other Dlookup formula's to work with lots of messing around. I am hoping someone can tell me what I am missing. I am going to break this down as I understand it and then maybe someone could explain. "ItemNumber=" this is the text box that will be filled in with the reusult of this formula. "Dlookup("[itemnumber]","[Shoporderstatus]" this is the field name and the name of the table that I am pulling the data from. "[shopordernumber]= " & [Forms]![shop_floor_data_entry]![shopordernumber]) is (shopordernumber) field name in the [shoporderstatus] table and the & [Forms]![shop_floor_data_entry]![shopordernumber]) part is [shopordernumber] is the name of my combo box on form [shop_floor_data_entry] Does that make any sense at all? I have this in the after update event in the shopordernumber combo box.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
If [Forms]![shop_floor_data_entry]![shopordernumber] is a number the following should work...
Code:
ItemNumber = DLookup("[itemnumber]", "[shoporderstatus]", "[shoporderstatus]![shopordernumber]= " & [Forms]![shop_floor_data_entry]![shopordernumber])

If [Forms]![shop_floor_data_entry]![shopordernumber] is text the following should work...
Code:
ItemNumber = DLookup("[itemnumber]", "[shoporderstatus]", "[shoporderstatus]![shopordernumber]= '" & [Forms]![shop_floor_data_entry]![shopordernumber] & "'")
 
Upvote 0
Thanks for responding, I have this and is not working,

Code:
Private Sub Shop_Order_Number_AfterUpdate()
Item_Number = DLookup("[itemnumber]", "[shoporderstatus]", "[shoporderstatus]![shopordernumber]= " & [Forms]![shop_floor_data_entry]![ShopOrderNumber])
End Sub

The "Item_Number =" in the beginning - is "Item_Number" the name of my text box in the current form? so the Dlookup formula following fills in that text box with the answer?
 
Upvote 0
One more change but it still don't work,
Code:
Private Sub Shop_Order_Number_AfterUpdate()
Item_Number = DLookup("[itemnumber]", "[shoporderstatus]", "[shoporderstatus]![shopordernumber]= " & [Forms]![shop_floor_data_entry]![Shop_Order_Number])
End Sub
 
Upvote 0
I am getting this error, " Microsoft can not find referenced form 'shop_floor_data_entry'
 
Upvote 0
Ok this worked:I guess I didn't need the underscores. Thanks for your help.

Code:
Private Sub Shop_Order_Number_AfterUpdate()
Item_Number = DLookup("[itemnumber]", "[shoporderstatus]", "[shoporderstatus]![shopordernumber]= " & [Forms]![Shop Floor Data Entry]![Shop Order Number])
End Sub
 
Upvote 0
Spaces can be confusing at times. That is why it is best to avoid them whenever possible.

Generally, if the are contained within brackets they will display exactly like they are in Access, with spaces. If they are in code that doesn't use brackets, underscores will need to be in there. However, even with the underscores I have seen the code error out, so like I said, I usually avoid spaces altogether and just change the captions on my forms to something meaningful.
 
Upvote 0
I learned that unfortunately after this database was to far along to change back, but moving forward in anything I create I can guarantee there will be no spaces.

Thanks again to all you on this board for your help.
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,548
Members
452,927
Latest member
rows and columns

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top