VBA Select Query with Variable

G

Guest

I am not sure what I am doing wrong, but I am getting the error "Too few
parameters. Expected 1". What I am trying to do here is I have a routine
that generates the network name of the computer. This is called
"AuditTrailRealTime". It passes the computer name to the public variable
"Value123". I then pass this to the variable "Value1".

I then want to take it and use the sql statement below which will basically
look up that value in a table and return one record, it will always be one
record or no records. Then I need to get the values from two fields of the
record, those values will be in the fields "Area" and "Type1". I then use
these values for other things. Below is the code as I have it now, and I
really can't figure out where I am going wrong with this, any help would be
greatly appreciated as I think I am close, but can't get it figured out.
Where do I go from here?


Dim Value1 As String
Dim db As Database
Dim rs As Recordset
Dim sql As String

AuditTrailRealTime

Value1 = Value123

sql = ("SELECT RT_List_Computers.ComputerName, RT_List_Computers.Type1,
RT_List_Computers.Area FROM RT_List_Computers WHERE
(((RT_List_Computers.ComputerName)= " & Value1 & "));")
'Debug.Print sql

Set db = CurrentDb
Set rs = db.OpenRecordset(sql)
 
G

Guest

James,

Check all your field names are spelt correctly.

You could also enclose Value1 in apostrophes in the SQL:

(((RT_List_Computers.ComputerName)= '" & Value1 & "'));")

Good Luck!

Steve.
 

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

Top