|
Guest
Posts: n/a
|
Hard to read through all that and find a syntax problem; however, I do see
one problem. You have a field in your recordset with the name Date. Date is
an Access reserved word and will cause errors. It may cure your problem is
you change
& "RepName ," & "Date ," & "ANI ," & "TransType ," _
to
& "RepName ," & "[Date] ," & "ANI ," & "TransType ," _
Avoid using any reserved words as field names. First, Date is a reserved
work, it also means nothing. What date? ExpirationDate, EntryDate,
TransactionDate. Meaningful names are very helpful to you and anyone else
reading your code. It is also a good idea to use a standard naming
convention that will prevent even ambiguous names from causing problems, like
dtmDate or dteDate.
Here is a site I hope will be helpful to you
http://msdn.microsoft.com/archive/de...n_20naming.asp
"Lisa" wrote:
> I have this code that was used to insert fields from a form to a table, when
> I click on the button to add the data to the table I am getting an error
> "Error in INSERT TO Statement"
>
> I have copied this code from another form that it worked in, just changed to
> form fields for the new form and it's not working. I didn't create the code
> and not sure how to check where the error is. Can anyone help?
>
> Private Sub Command122_Click()
> On Error GoTo Err_btnSave_Click
> Dim strSQL As String
> Dim numMatching As Integer
> Dim Recordset As Recordset
> Dim conDatabase As ADODB.Connection
> Set conDatabase = CurrentProject.Connection
>
>
> Dim Month As String
> RepNm = cmbRep.Value
> If RepNm = "" Then
> MsgBox "Choose the Reps name you are quality checking from the
> dropdown."
> Else
>
> strSQL = "Insert into TBL_QualitySales ( " _
> & "RepName ," & "Date ," & "ANI ," & "TransType ," _
> & "Q1_Answer ," & "Q1_Comment ," & "Q2_Answer ," &
> "Q2_Comment ," _
> & "Q3_Answer ," & "Q3_Comment ," & "Q4_Answer ," &
> "Q4_Comment ," & "Q5_Answer ," & "Q5_Comment ," & "Q6_Answer ," & "Q6_Comment
> ," & "Q7_Answer ," & "Q7_Comment ," _
> & "Q8_Answer ," & "Q8_Comment ," & "Q9_Answer ," &
> "Q9_Comment ," & "Q10_Answer ," & "Q10_Comment ," & "Q11_Answer ," &
> "Q11_Comment ," & "Q12_Answer ," & "Q12_Comment ," _
> & "Q13_Answer ," & "Q13_Comment ," & "Q14_Answer ," &
> "Q14_Comment ," & "Q15_Answer ," & "Q15_Comment ," & "Q16_Answer ," &
> "Q16_Comment ," & "Q17_Answer ," & "Q17_Comment ," _
> & "Q18_Answer ," & "Q18_Comment ," & "Q19_Answer ," &
> "Q19_Comment ," _
> & "Q20_Answer ," & "Q20_Comment ," & "Q21_Answer ," &
> "Q21_Comment ," _
> & "Q22_Answer ," & "Q22_Comment ," & "Q23_Answer ," &
> "Q23_Comment) " _
> & "Values(" _
> & cmbRep & "," & "'" & txtqdate & "'," & "'" & txtANI &
> "'," & "'" & cbtrans & "'," _
> & "'" & FrmQ1_Results & "'," & "'" & txt_Q1Comments & "',"
> & "'" & FrmQ2_Results & "'," & "'" & txt_Q2Comments & "'," _
> & "'" & FrmQ3_Results & "'," & "'" & txt_Q3Comments & "',"
> & "'" & FrmQ4_Results & "'," & "'" & txt_Q4Comments & "'," & "'" &
> FrmQ5_Results & "'," & "'" & txt_Q5Comments & "'," & "'" & FrmQ6_Results &
> "'," & "'" & txt_Q6Comments & "'," & "'" & FrmQ7_Results & "'," & "'" &
> txt_Q7Comments & "'," _
> & "'" & FrmQ8_Results & "'," & "'" & txt_Q8Comments & "',"
> & "'" & FrmQ9_Results & "'," & "'" & txt_Q9Comments & "'," & "'" &
> FrmQ10_Results & "'," & "'" & txt_Q10Comments & "'," & "'" & FrmQ11_Results &
> "'," & "'" & txt_Q11Comments & "'," & "'" & FrmQ12_Results & "'," & "'" &
> txt_Q12Comments & "'," _
> & "'" & FrmQ13_Results & "'," & "'" & txt_Q13Comments &
> "'," & "'" & FrmQ14_Results & "'," & "'" & txt_Q14Comments & "'," & "'" &
> FrmQ15_Results & "'," & "'" & txt_Q15Comments & "'," & "'" & FrmQ16_Results &
> "'," & "'" & txt_Q16Comments & "'," & "'" & FrmQ17_Results & "'," & "'" &
> txt_Q17Comments & "'," _
> & "'" & FrmQ18_Results & "'," & "'" & txt_Q18Comments &
> "'," & "'" & FrmQ19_Results & "'," & "'" & txt_Q19Comments & "'," _
> & "'" & FrmQ20_Results & "'," & "'" & txt_Q20Comments &
> "'," & "'" & FrmQ21_Results & "'," & "'" & txt_Q21Comments & "'," _
> & "'" & FrmQ22_Results & "'," & "'" & txt_Q22Comments &
> "'," & "'" & FrmQ23_Results & "'," & "'" & txt_Q23Comments & "'" _
> & ")"
> 'MsgBox "SQL: " & strSQL
> conDatabase.Execute (strSQL)
> MsgBox "Added quality data for Rep: " & RepName & " and Date:
> " & Date
> DoCmd.Close acForm, "FRM_Sales", acSaveNo
>
> End If
>
|
|