Run time error 3343 unrecognized database format

0 votes
Sub Export1line()

    Application.ScreenUpdating = False

    Dim db As Database
    Dim rs As DAO.Recordset
    
    Set db = OpenDatabase("FilePath")
    Set rs = db.OpenRecordset("TargetTableName", dbOpenTable)

    rs.AddNew
    rs.Fields("Column1") = Worksheets("To Export").Range("A2").Value
    rs.Fields("Column2") = Worksheets("To Export").Range("B2").Value
    rs.Fields("Column3") = Worksheets("To Export").Range("C2").Value
    rs.Fields("Column4") = Worksheets("To Export").Range("D2").Value
    rs.Fields("Column5") = Worksheets("To Export").Range("E2").Value
    rs.Fields("Column6") = Worksheets("To Export").Range("F2").Value
    
    rs.Update

    rs.Close
    db.Close

    Application.ScreenUpdating = True

End Sub

No matter whatever file path I choose when trying to have an excel file write to an Access database, I always receive a 3343 error stating that the path is in an unknown format.

The target database was changed to.mdb files, but I still receive the same problem.

Mar 25, 2023 in Others by Kithuzzz
• 38,000 points
722 views

1 answer to this question.

0 votes

Try using ADODB.

Option Explicit

Sub Export1line()

    Const DB = "FilePath"
    Const TABLE = "TargetTableName"

    Dim cn As Object, rs As Object
    Dim i As Long, r As Long, n As Long
    Dim col, val(5)
    col = Array("Column1", "Column2", "Column3", _
                "Column4", "Column5", "Column6")
    
    Set cn = CreateObject("ADODB.Connection")
    With cn
        .ConnectionString = "Provider=Microsoft.ace.OLEDB.12.0;Data Source=" & DB
        .Open
    End With

    Set rs = CreateObject("ADODB.Recordset")
    rs.Open TABLE, cn, 2, 2, 2 'adOpenDynamic, adLockPessimistic, adCmdTable

    With Worksheets("To Export")
        For r = 2 To 2 ' 1 row
            For i = 0 To 5
                val(i) = .Cells(r, i + 1).Value
            Next
            ' add record
            rs.AddNew col, val
            n = n + 1
        Next
    End With
    rs.Close
    cn.Close
    MsgBox n & " records added to " & TABLE
  
End Su
answered Mar 25, 2023 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
1 answer

Excel to Word Macro resulting in Run-time error 462

Are you attempting this (UNTESTED)? I've commented ...READ MORE

answered Jan 29, 2023 in Others by narikkadan
• 63,600 points
967 views
0 votes
1 answer

I am trying to run following command But I end up with an error :

Hii Nishant, You are running this command inside ...READ MORE

answered Apr 6, 2020 in Others by Niroj
• 82,840 points
1,881 views
0 votes
1 answer

ERROR: You need elevated Administrator privileges in order to run this script.

Hi@akhtar, I guess you are trying to run ...READ MORE

answered Sep 8, 2020 in Others by MD
• 95,460 points
2,126 views
0 votes
1 answer
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
1,260 views
0 votes
1 answer

How to load file to Excel Power query from SFTP site

Currently, I don't think there is a ...READ MORE

answered Dec 3, 2018 in Power BI by Upasana
• 8,620 points
3,698 views
0 votes
1 answer

Using VBA Excel to create a gramatically correct list

The Excel AND function is a logical ...READ MORE

answered Feb 9, 2022 in Others by gaurav
• 23,260 points
978 views
0 votes
2 answers

How to copy a formula horizontally within a table using Excel VBA?

Hi so basically, create an adjacent column ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,690 points
1,091 views
0 votes
1 answer

VBA code to select only a table. I am getting a Run-time error '1004'; Method 'Range' of object'_Global' failed

No copy/paste, just direct assignment use.Value Sub Final_Report() ...READ MORE

answered Jan 13, 2023 in Others by narikkadan
• 63,600 points
1,168 views
0 votes
1 answer

Excel VBA - Subscript Out of Range Error (Run Time: Error 9)

Set rangePartner = Range(Partner.Cells(2, 2), Partner.Cells(2, 2).End(xlDown)) Needs ...READ MORE

answered Jan 21, 2023 in Others by narikkadan
• 63,600 points
1,040 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP