TheCandyman
Technical User
I'm trying to do a insert in a table, if i get the output from the code and run that sql line in a query it updates the table. If it's in the vba code it doens't work, so i'm not sure what i can do to make it work. All values are numbers. The problem is in the Year, if i take that out it works. Year is a lookup value from another table, values are 2007, it's ID is 2082530338.
The SQL statement that runs fine if i paste it into a query but wont run in the code
Error
Code:
Set adoCmd3 = New ADODB.Command
Set adoRst3 = New ADODB.Recordset
Set adoConn3 = CurrentProject.Connection
strSQL3 = "Insert Into tblDues (AzDAAID, Year, Yearly_Dues, MethodPaidID) "
strSQL3 = strSQL3 & "Values(" & adoRst2.Collect("AzDAAID") & ""
strSQL3 = strSQL3 & "," & Me.cboToYear.Value & ""
strSQL3 = strSQL3 & "," & Me.cboToDues.Value & ""
strSQL3 = strSQL3 & ",4)"
Set adoCmd3 = New ADODB.Command
With adoCmd3
.ActiveConnection = adoConn3
.CommandText = strSQL3
.CommandType = adCmdText
.Execute , , adExecuteNoRecords
End With
Set adoCmd3 = Nothing
adoRst2.MoveNext
The SQL statement that runs fine if i paste it into a query but wont run in the code
Code:
Insert Into tblDues (AzDAAID, Year, Yearly_Dues, MethodPaidID) Values(445,2082530338,40,4)
Error
Code:
run-time error '-2147217900 (80040e14)':
Syntax error in INSERT INTO statement.