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
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