Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT INTO statement question

Status
Not open for further replies.

jerseyboy

Technical User
Mar 7, 2002
127
US
I can't see the forest for the trees!

I am in VB trying to execute a [DoCmd.RunSQL strSQL] statement

Here is the code and the resulting msgbox:

_____________________________________

Private Sub cmdAddOne_Click()
Dim strSQL As String
Dim intContactID As Integer
Dim intEventID As Integer

intEventID = Me.lstAvailable.Column(0)
intContactID = Me.lstAvailable.Column(1)

strSQL = """" & "INSERT INTO tblEventAttendees ([EventID],[ContactNumber]) VALUES (" & """" & intEventID & """" & " , " & """" & intContactID & """" & ")" & """;"

MsgBox strSQL

'DoCmd.RunSQL strSQL

End Sub

________________________________________________

msgbox Result:
"INSERT INTO tblEventAttendees ([EventID],[ContactNumber]) VALUES ("1" , "1")";

___________________________________________________________

What simple thing(s) am I missing? I am using Access Developers Handbook 1 (page 179) as a reference, but obviously I am missing something.

Thanks for the help :)


Thanks! JerseyBoy
Remember: self-praise is no recommendation
 
My guess is that you have put quotes around number values...

"INSERT INTO tblEventAttendees ([EventID],[ContactNumber]) VALUES (1 , 1)";

or you need single quotes so you don't screw up your string

"INSERT INTO tblEventAttendees ([EventID],[ContactNumber]) VALUES ('1' , '1')"; Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
 
I think mwolf00 is correct but I think you will have to try something like this.

strSQL = "INSERT INTO tblEventAttendees ([EventID],[ContactNumber]) VALUES (" & intEventID & " , " & intContactID & ")"

I haven't used VB in a long time so I don't know if that makes a difference but if you were running this in Access the above would be correct for numeric datatypes.

Paul
 
Thank you both, I did get it to work..

Here is the final statement for those who may follow this thread:

strSQL = "INSERT INTO tblTEMPEventAttendees ([EventID],[ContactNumber]) VALUES (" & "'" & strEventID & "'" & " , " & "'" & intContactID & "'" & ")" & ";"

The SINGLE quotes made a difference as well as the final ";
" was incorrect.


JerseyBoy
Remember: self-praise is no recommendation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top