-
Hello VB users,
I am trying to insert via SQL a record in my table.
Source:
Private Sub Form_Load()
Set DB = OpenDatabase("c:\q.mdb")
Dim QQQ As String
QQQ = "test"
DB.Execute " INSERT INTO MyTable " _
& "(MyField) VALUES " _
& "(QQQ);"
End Sub
error message: Too few parameters!
Normaly is variable QQQ a hard coded string like: "Test".
How do I change the SQL code so it accept a varible?
Thanks for reading,
Michelle.
-
The sting QQQ needs to be in quotes
I usualy do it liek this:
const Quote = """"
DB.Execute "INSERT INTO MyTable(MyField) VALUES(" & quote & QQQ & quote & ");"
-
Michelle--
Mark is correct that QQQ needs "'s.
The following snippet is a little more complicated than his, but I think by actually writing out your SQL statement as below, it's a little clearer what's going on... I hope.
--Carl
Dim dbInsert As Database
Dim qdfInsert As QueryDef
Dim insSQL As String ' SQL statement for appending data
Dim QQQ As String
QQQ = "test"
insSQL = "INSERT INTO MyTable (MyField) VALUES ('" & QQQ & "');"
Set dbInsert = OpenDatabase("c:\q.mdb")
' Create the QueryDef object to append the data
Set qdfInsert = dbInsert.CreateQueryDef("", insSQL)
qdfInsert.Execute
qdfInsert.Close
Edited by cfmoxey on 03-10-2000 at 05:02 PM
-
Hello Mark Sreeves & cfmoxey,
Thanks for your information.
Michelle.