|
-
Mar 8th, 2000, 06:07 PM
#1
Thread Starter
Hyperactive Member
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.
-
Mar 8th, 2000, 06:41 PM
#2
Frenzied Member
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 & ");"
-
Mar 8th, 2000, 09:14 PM
#3
Member
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
-
Mar 9th, 2000, 03:50 PM
#4
Thread Starter
Hyperactive Member
Hello Mark Sreeves & cfmoxey,
Thanks for your information.
Michelle.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|