By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,106 Members | 2,335 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,106 IT Pros & Developers. It's quick & easy.

How to use "Insert Into" to programatically insert multiple fields into a table

P: n/a
CFW
I use the following flawlessly to insert a single field:

strSQL = "Insert into [_tblCasket] (Casket) Values " _
& "(" & conQuote & NewCasket & conQuote & ")"
Set db = CurrentDb

If MsgBox(NewCasket & " is not in the list. Do you want to add "
& NewCasket & _
" as a new Casket/Container in the list?", vbYesNo, _
"Add a Casket/Container") = vbYes Then
db.Execute strSQL
Response = acDataErrAdded
Else
Response = acDataErrDisplay
End If

I can't figure out the syntax to insert into multiple fields?! Can I?
TIA!
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
From what I can tell you are simply not specifying multiple fields
there.
Then your values appear to be improperly formatted.

try:

strSQl = "INSERT INTO _tblCasket (field1, field2, field3 ... ) VALUES
{'" & varField1 & "' , '" & varField2 & "' , '" & varField3 & "');"

such that the concatenated string has the proper SQL format:

INSERT INTO _tblCasket (field1,field2,field3)
VALUES ('stringvalue1',#datevalue2#,numvalue3);

keeping in mind that only string values need to be quoted, dates
should be bracketed by #01/01/2003# to preserve their formatting and
numbers need no qualifiers at all.

also remember to use [] if your field names match internal keywords
such as [Date] etc.

regards,

john OBrien
Applied Computer Science

CFW <cf****@comcast.net> wrote in message news:<ts********************************@4ax.com>. ..
I use the following flawlessly to insert a single field:

strSQL = "Insert into [_tblCasket] (Casket) Values " _
& "(" & conQuote & NewCasket & conQuote & ")"
Set db = CurrentDb

If MsgBox(NewCasket & " is not in the list. Do you want to add "
& NewCasket & _
" as a new Casket/Container in the list?", vbYesNo, _
"Add a Casket/Container") = vbYes Then
db.Execute strSQL
Response = acDataErrAdded
Else
Response = acDataErrDisplay
End If

I can't figure out the syntax to insert into multiple fields?! Can I?
TIA!

Nov 12 '05 #2

P: n/a
you mean you couldn't copy anything from an Insert query? Or the help
file? The help file is your friend!

INSERT INTO table (field1, field2, field3...) VALUES
(value1,value2,value3)
Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.