Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert Into query 1

Status
Not open for further replies.

davyre

Programmer
Oct 3, 2012
197
AU
I got a simple query to insert some numbers to a table in access. Here is the code:
Public Sub TryInsertIntoTable()
Dim dbs As Database
Set dbs = CurrentDb

Dim query As String
Dim x, y, z As Integer
x = 123
y = 321
z = 213

dbs.Execute "INSERT INTO Table1 ([Col 2],[Col 3],[Col 4]) VALUES (x,y,z)"

End Sub

Why it says runtime error 3061 too few parameters expected 3? If I change the VALUES to the actual data, it worked. The case is I want to use the variables (in this case x, y, z) to be inputted into the table.
I tried using --> VALUES('x', 'y', 'z')", it doesnt say any errors but in the table, there is no value inserted (as the range has number datatype).
Any help?Thanks
 
dbs.Execute "INSERT INTO Table1 ([Col 2],[Col 3],[Col 4]) VALUES (" & x & "," & y & "," & z & ")"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Do it this way.
Code:
dbs.Execute "INSERT INTO Table1 ([Col 2],[Col 3],[Col 4]) " & _
            "VALUES (" & x & ", " & y & ", " & z & ")"
 
thanks guys. Golom's post was a success. I didn't know if spaces were that important. When I typed the PHV's, it still gave me error. I dont know if its just me or not.
Anw thanks!
 
The only difference between PHV's and mine is the spaces after the commas and they are not required. Probably just a typo.
 
When I typed the PHV's, it still gave me error
Which error ?
 
it says something like expression expected or anything else like that. Maybe just my typo :s. Anw thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top