troubleshooting Question

Run-time error '-2147217900 (80040e14)': Syntax error in INSERT INTO statement(What wrong with Insert statement:)

Avatar of ca1358
ca1358 asked on
Microsoft ExcelMicrosoft Access
16 Comments1 Solution352 ViewsLast Modified:
I loaded the Access but the Excel document would not upload(Insert into Acess _Part.xltm) so I Print scrren it and uploaded it.

What wrong with Insert statement:

Code:
Sub Macro4()

   Dim appAccess As Object
   
Set appAccess = CreateObject("Access.Application")

 
 Call appAccess.OpenCurrentDatabase( _
 "\\DTCHYB-ILSP001\C_MTG_Groups\Mandatory\Analysts - Working Files\Carol\Test\Expert\TestAccess.accdb")
   appAccess.Visible = True

   appAccess.UserControl = True

    ' open table("ExcelToAccess")
 
appAccess.DoCmd.OpenTable "ExcelToAccess"

  Range("A5:H5").Select
    Selection.Copy
   
    CopyToAccessTable
   
End Sub


Sub CopyToAccessTable()

Dim sql As String, accFilePath As String
Dim cnn As ADODB.Connection

        accFilePath = ActiveWorkbook.Path & "\TestAccess.accdb"

    sql = "INSERT INTO  ExcelToAccess ( [Test], [TestA], [TestB],[TestC],[TestD],[TestE], ) IN '" & "'" _
                & " Values(" & Range("A5") & ", '" & Range("B5") & "', '" & Range("C5") & "', '" & Range("D5") & "', '" & Range("E5") & "', '" & Range("F5") & "', '" & Range("G5") & "', '" & Range("H5") & "'  )"
               
        Set cnn = New ADODB.Connection
        cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & accFilePath & ";Persist Security Info=False;"

        If Not (cnn Is Nothing) Then
            'Execute Sql
            cnn.Execute (sql)
            'Close
            cnn.Close
        End If
        Set cnn = Nothing

End Sub
TestAccess.accdb
Excel.docx
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 16 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 16 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros