VBA help

  • Thread starter Thread starter Phil
  • Start date Start date
P

Phil

can someone please convert the following expression into VB code please

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

Thanks
 
Note quite sure of the question??

Your expression as is should work in VBA......

eg:


dim curUnitPrice as currency

curUnitPrice = DLookUp("[UnitPrice]","[Products]"," [Products]![ProductID]
=
Forms![Order Details]![ProductID]")
 
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])
 
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top