INSERT INTO syntax problem

  • Thread starter Thread starter Andrew Gould
  • Start date Start date
A

Andrew Gould

Can some please help me with the syntax. It says, "Syntax error in INSERT
INTO statement." What's wrong with my strSQLInsert statement? Thanks

Dim ContactID As Integer
Dim strGradDate As String
Dim strMajor As String
Dim strMinor As String
Dim strSQLInsert As String
Dim strSQLDelete As String

ContactID = Me.CONTACT_Contact_ID
strGradDate = Me.txtStudentGradDate
strMajor = Me.txtStudentMajor
strMinor = Me.txtStudentMinor

strSQLInsert = "INSERT INTO tblALUMNI (CONTACT_Contact_ID,
ALUMNI_GradDate, ALUMNI_Major, ALUMNI_Minor) VALUES '" & ContactID & "', '"
& strGradDate & "', '" & strMajor & "', '" & strMinor & "';"

DoCmd.RunSQL strSQLInsert
 
Try changing how you pass your integer and date.

Do place parentheses around the VALUES values. Do *not* place apostrophes around your integer. *Do* place pound signs (i.e., "#") around your date.

For example:

INSERT INTO tblTable ( field1, field2 ) VALUES ( data1, data2);

VALUES (" & ContactID & ", #"
& strGradDate & "#, '" & strMajor & "', '" & strMinor & "');"

I trust this will correct your issues.

David Atkins, MCP
 
Back
Top