Dlookup resulting in null value

Gavx

Registered User.
Local time
Tomorrow, 05:00
Joined
Mar 8, 2014
Messages
155
I am trying to run this code but getting a run time error 94 - null value - when it shouldn't be.
I am thinking I have written the Dlookup incorrectly?

Code:
Private Sub txtProductName_Click()
Dim iProdType As Integer
Dim ProductID As Integer


iProdType = DLookup("ProductTypeID", "tblProduct", "ProductID" = Forms![frmBooking]![cboProductID].[Value])

Note ProductID in an integer

How can I diagnose this or what could the solution be?

thanks
 
the = needs to be in quotes, try

iProdType = DLookup("ProductTypeID", "tblProduct", "ProductID = " & Forms![frmBooking]![cboProductID])

And if this bit of code is in the same form as cboProductID then all you need is

iProdType = DLookup("ProductTypeID", "tblProduct", "ProductID = " & [cboProductID])

Note you do not need the .value - this is the default property
 
Thanks CJ

I tried
Code:
iProdType = DLookup("ProductTypeID", "tblProduct", "ProductID = " & Forms![frmBooking]![cboProductID])

because this code runs in a subform to frmBooking which is where cboProductID is located.

I am now receiving the error 3075 Syntax error (missing operator) in query expression 'ProductID = '.
 
sounds like your control cboProductID is null (or perhaps named something else)
 
If I put a breakpoint on that statement and run the code and hover the cursor over the " & Forms![frmBooking]![cboProductID]) part the following displays under teh cursor;

Forms![frmBooking]![cboProductID]="482" which is what I expect. But when I hover the cursor over iProdType the value of 0 is reported.
 
iProdType will be 0 until the dlookup line of code has been executed - hit F8 to move to the next line then hover over iProdType

And just to confirm, there is a ProductID in tblProduct numbered 482 and a field called ProductTypeID?
 

Users who are viewing this thread

Back
Top Bottom