VBA help

P

Phil

can someone please convert the following expression into VB code please

DLookUp("[UnitPrice]","[Products]"," [Products]![ProductID] =
Forms![Order Details]![ProductID]")

Thanks
 
F

fredg

can someone please convert the following expression into VB code please

DLookUp("[UnitPrice]","[Products]"," [Products]![ProductID] =
Forms![Order Details]![ProductID]")

Thanks
The value in Forms![Order Details]![ProductID] must be concatenated
into the where cluse.

If ProductID is a Number datatype ....
= DLookUp("[UnitPrice]","[Products]"," [Products]![ProductID] = " &
Forms![Order Details]![ProductID])

If ProductID is Text datatype ....
= DLookUp("[UnitPrice]","[Products]"," [Products]![ProductID] = '" &
Forms![Order Details]![ProductID] & "'")

Note: If the above DLookup is written in the Order Details code
window, you can substitute the Me! keyword.

= DLookUp("[UnitPrice]","[Products]"," [Products]![ProductID] = " &
Me![ProductID])
 
J

Josh D

That cam be translated into SQL statement that can be used by VB as such:
"SELECT UnitPrice FROM Products WHERE ProductID = " & Forms![Order
Details]![ProductID]

The ProductID field in the form Order Detail must be numeric. If it is a
string modify to the following

"SELECT UnitPrice FROM Products WHERE ProductID = " & chr(34) &
Forms![Order Details]![ProductID] & chr(34)
 
Top