Syntax error in Insert Into Satement

Keith

Registered User.
Local time
Today, 03:33
Joined
May 21, 2000
Messages
129
I am running the following code from a command button on a form. I am trying to write a number of records to a table dependent on the value of a text box (txtQuantityVeh) on the form. my code is:

Dim SVE As String, number As Long
For number = 1 To Me.txtQuantityVeh.Value
SVE = "Insert into tblMovement(HireId,VehNo,)" & " Values ( ' " & [txtHireId].Value & " ' & ' " & number & " ' )"
Debug.Print (SVE)
DoCmd.SetWarnings False
DoCmd.RunSQL (SVE)
number = number + 1
Next number
DoCmd.SetWarnings True

I get an error 'Syntax Error in INSERT INTO STATEMENT'
The immediate window shows SVE as:

Insert into tblMovement(HireId,VehNo,) Values ( ' 82 ' & ' 1 ' )

I get the same error whatever value txtQuantity is. I would appreciate any guidance as to what I am doing wrong
 
Thanks Matt well spotted.
However I now get Runtime Error '3346' Number of query values and destination fields are not th same.
 
There's no comma in the VALUES clause. It should be there instead of "&".
 
Thanks Paul & Matt - Problem solved
 

Users who are viewing this thread

Back
Top Bottom