Looking Up a Field Value Based on Variable

  • Thread starter Thread starter John C.
  • Start date Start date
J

John C.

I have a table. It contains ComputerID and Location.

I have a subroutine that reads the .LDB file for a
database I administer. It determines each Computers ID
that is using the DB.

The subroutine creates a list, which populates a list box
(values seperated by a semi-colon).

As each Computers ID is determined, I want to lookup the
associated location, and populate another list box.

I have tried the following:
sLocation = DLookup
("[Location]", "ComputerLocations", "[ComputerID] = " &
sLogStr)

[Location] and [ComputerID] are fields within
the "ComputerLocations" table.

sLogStr is the variable which contains the Computers ID.

I receive the following ERROR message:
Error: 64479
The expression you entered as a query parameter produced
this error: 'The object doesn't contain the Automation
object 'PC42218.''

PC42218 is a computer ID.
 
For Text value "PC42218", you need to enclose it in single-quotes or
double-quotes like:

sLocation = DLookup("[Location]", "ComputerLocations",
"[ComputerID] = '" & sLogStr & "'")
 
Hi John,

Since ComputerID is not a number,
you will need to surround sLogStr with single quotes
in your DLookup WHERE clause.

sLocation = DLookup("[Location]", "ComputerLocations", _
& "[ComputerID] = '" & sLogStr & "'")

or

sLocation = DLookup("[Location]", "ComputerLocations", _
& "[ComputerID] = " & Chr(39) & sLogStr & Chr(39))

or

sLocation = DLookup("[Location]", "ComputerLocations", _
& "[ComputerID] = " & Chr(34) & sLogStr & Chr(34))


I don't know why you could not understand that
from the clear error message. 8-)

Good luck,

Gary Walter
 
Back
Top