insert into

tubar

Registered User.
Local time
Today, 13:16
Joined
Jul 13, 2006
Messages
190
In the following code an error occurs where “release" of “cd release" is high lighted and a compile error expected: end of statement appears

strSQL = "INSERT INTO " _
& "tblMultiplLables(cd release, dvd release , " _
& "customers, upc, group 1, group 2, " _
& "VALUES(" _
& "'" & Me!cd release & "', " _
& "'" & Me!dvd release & "', " _
& "'" & Me!customers & "', " _
& "'" & Me!upc & "', " _
& "'" & Me!group 1 & "', " _
& "'" & Me!group 2 & "') "
 
You would have to bracket all the field names containing the inadvisable spaces.
 
now i get the error
3134 syntaxerror in insert into statement

Private Sub cmdPrintMultipleLabel_Click()
'Print multiple labels for current record.

Dim bytCounter As Byte
Dim strSQL As String
On Error GoTo errHandler
If IsNull(Me!txtNumberOfLabels) Then
MsgBox "Please indicate the number of labels you want to print", _
vbOKOnly, "Error"
DoCmd.GoToControl "txtNumberOfLabels"
Exit Sub
End If

'Delete previous label data.
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE FROM tblMultiplLables"

'Set up label record.
strSQL = "INSERT INTO " _
& "tblMultiplLables([cd release], [dvd release] , " _
& "[customers], [upc], [group 1], [group 2], " _
& "VALUES(" _
& "'" & Me![cd release] & "', " _
& "'" & Me![dvd release] & "', " _
& "'" & Me![CUSTOMERS] & "', " _
& "'" & Me![upc] & "', " _
& "'" & Me![group 1] & "', " _
& "'" & Me![group 2] & "') "

Debug.Print strSQL


'Populate table with records.
For bytCounter = 1 To Me!txtNumberOfLabels.Value
DoCmd.RunSQL strSQL
Next

DoCmd.SetWarnings True

DoCmd.OpenReport "8160 00 upc cd cmb", acViewPreview

Exit Sub

errHandler:

MsgBox Err.Number & ": " & Err.DESCRIPTION, vbOKOnly, "Error"
DoCmd.SetWarnings True

End Sub
 
Well, the way to debug is to examine the SQL from the debug.Print. I can already see a parentheses problem and a bonus comma.
 

Users who are viewing this thread

Back
Top Bottom