DLookUp in simple(sic) terms

TheToeOfPooh

Active Member
Joined
May 21, 2004
Messages
254
From reading through all the other posts I realise we have a Possible Error Between Chair And Keyboard here -

On a Form called frmBookIN
I have a ComboBox called cboProductID
Source Table is tblMasterStockCodesDescriptions
Source Field is ProductID

This bit works fine using a Row Source of
SELECT[tblMasterStockCodesDescriptions].[ProductID]FROM tblMasterStockCodesDescriptions;

What I now need to do is
When the user selects a ProductID
on the same form
in another Text(?) Box called txtProductDescription
display the corresponding Product Description
Source Table is same table as the ComboBox
Source Field is ProductDescription

Any help would be very appreciated.Please assume minimal knowledge here in grey, overcast Worcester.

Bernard
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
The following gives me an #Error in the Product Description box
with or without a selection being made in the ID ComboBox.

Could someone please see if my syntax is corect:
If relevant - All Field formats within Table are Text

=DLookUp("ProductDescription]","tblMasterStockCodesDescriptions","[ProductID]=forms![frmBookIN]![ProductID")

Bernard
 
Upvote 0
Is what you posted exactly what you have?

Try this

=DLookUp("[ProductDescription]","tblMasterStockCodesDescriptions","[ProductID]"=Forms![frmBookIN]![ProductID])
 
Upvote 0
The following just gives me the ProductDescription of the first item in the Table no matter which product code I enter:


=DLookUp("[ProductDescription]","tblMasterStockCodesDescriptions","[ProductID]=[ProductID]")

But at least it's better than #Error to look at :confused:

Bernard
 
Upvote 0
Whoops what I posted was slightly wrong. Try

=DLookUp("[ProductDescription]","tblMasterStockCodesDescriptions","[ProductID]= " & Forms![frmBookIN]![ProductID])

I'm assuming ProductID is a number.
 
Upvote 0
Shouldn't be a problem just need to add quotes:

Try

=DLookUp("[ProductDescription]","tblMasterStockCodesDescriptions","[ProductID]='" & Forms![frmBookIN]![ProductID] & "'")

BTW it's ' rather than " that has been added.
 
Upvote 0
Norie

Still no joy - Just a blank txt box where the ProductDescription should be

I have even tried adding the following code to the frmBookIN

Private Sub ProductDescription_BeforeUpdate(Cancel As Integer)
On Error Resume Next
If ProductID > 0 Then
ProductDescription = DLookup("[ProductDescription]", "tblMasterStockCodesDescriptions", "[ProductID]= ' " & Forms![frmBookIN]![ProductID] & "'")
End If

End Sub


My apologise for turning this into a bit of a quest, but any toher tips please?

Bernard
 
Upvote 0
Have you checked the the code is working?

Is Forms![frmBookIN]![ProductID] returning the expected value?

I don't mean the DLookup, just that it is being triggered.

Also try Msgbox with the DLookUp.
 
Upvote 0

Forum statistics

Threads
1,221,816
Messages
6,162,148
Members
451,746
Latest member
samwalrus

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