0

I'm trying to update a table in Access, taking data from a range(rng) in Excel. I adapted a macro from Brad Importing Excel worksheet range to Ms Access Table but I'm receiving the Run-time error '3219'. If I substitute sqlTransferFromExcel = "UPDATE TableA T1 " with "Select FROM TableA T1 " it works. The issue I suppose is liked to the UPDATE statment. Here the code:

    Public Sub ImportFromWorksheet()
        Dim strFile As String, strCon As String, strMsg
        Dim sht As Worksheet
        Dim TipoRecordset As RecordsetTypeEnum
        Dim db_Open As Boolean, rs_Open As Boolean
        Dim rs As DAO.Recordset
        Dim nRows As Integer
        Dim getRecordset()
        
        Set sht = ActiveSheet
        strFile = sht.Parent.FullName
        strCon = "Excel 12.0;HDR=No;Database=" & strFile
    
        Dim strSql As String, sqlTransferFromExcel As String
    
        Dim row As Long
        row = 35
        Dim rng As String
        rng = "C30:E34" ',E29:E34"
       sqlTransferFromExcel = "UPDATE TableA T1 " & _
                "INNER JOIN (SELECT F1, F3 FROM [{{connString}}].[{{sheetName}}${{rng}}]) T2 " & _
                "ON T2.F1 = T1.blkName_Override " & _
                "SET " & _
                "T1.fldVaue_Override = T2.F3 "
        
        sqlTransferFromExcel = Replace(sqlTransferFromExcel, "{{rng}}", rng)
        sqlTransferFromExcel = Replace(sqlTransferFromExcel, "{{connString}}", strCon)
        sqlTransferFromExcel = Replace(sqlTransferFromExcel, "{{sheetName}}", sht.Name)
        open_DB (True)

        db.Execute sqlTransferFromExcel

 

End Sub
Giovanni
  • 61
  • 6
  • Ops that was one of my trying .. now is correct. Thanks – Giovanni Dec 30 '20 at 19:01
  • Thanks for your advice. Following your steps i got this :"You cannot edit this field because it resides in a linked excel spreadsheet. The ability to edit data in a linked excel spreadsheet has been disabled in this Access release". Any advice on the issue? – Giovanni Dec 30 '20 at 20:04
  • I could create a temp-table like and Delete it when finished, but not efficient... – Giovanni Dec 30 '20 at 20:16
  • That's right, thanks a lot – Giovanni Dec 30 '20 at 20:30
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/226646/discussion-between-giovanni-and-hansup). – Giovanni Dec 31 '20 at 05:53

0 Answers0