Anthony said:
I should say, I want to look up some values in a table.
something like how you would use DLookUp from a text box.
But from VB, I want to hard code it with vb, but don't
know how.
When you say "VB", do you mean VBA running inside Access -- code in a
standard module or behind a form or report? In that case, you can use
DLookup just as easily as in a controlsource expression. Here's a
simple example:
Dim curPrice As Currency
' ...
curPrice = DLookup("Price", "tblPrices", "ProductID=1234")
On the other hand, if by "VB" you mean a Visual Basic application, not
an Access application, then the DLookup function is not available -- but
you can open a recordset on a table in an .mdb file and do your lookup
that way. For example,
Dim curPrice As Currency
Dim db As DAO.Database
Dim rs As DAO.Recordset
' ...
Set db = DBEngine.OpenDatabase("C:\My Path\MyDB.mdb")
Set rs = db.OpenRecordset( _
"SELECT Price FROM tblPrices WHERE ProductID=1234")
If rs.EOF Then
curPrice = 0
Else
curPrice = rs!Price
End If
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
As you see, doing it in "true VB" is more complicated -- but this is
pretty much what the DLookup function does behind the scenes.