470,873 Members | 1,858 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,873 developers. It's quick & easy.

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

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
2 9493
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
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.

Similar topics

2 posts views Thread by newbie_mw | last post: by
2 posts views Thread by EricRobineau | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.