EXport MDB to CSV (1 Viewer)

Mari

New member
Local time
Today, 10:40
Joined
Sep 27, 2019
Messages
4
I have more than 4000 access(.accdb) files on my server. i have to export each file to separate CSV file. Is there anyway to export into CSV without manual effort(doing one by one)
 

isladogs

MVP / VIP
Local time
Today, 18:40
Joined
Jan 14, 2017
Messages
18,219
You can't export an Access file to CSV.
Do you mean export all the tables in each file to CSV?

BTW Welcome to AWF
 

jdraw

Super Moderator
Staff member
Local time
Today, 13:40
Joined
Jan 23, 2006
Messages
15,379
Not sure what you mean exactly by mdb to csv. As Colin said you can't simply convert accdb to csv.
To export each object with each database to text as a csv file, see this material from ghudson.

However, I note this is your post #1 - so before doing anything, tell us what you are trying to achieve in simple terms.There may be options.

Also, welcome to the forum.
 

Mari

New member
Local time
Today, 10:40
Joined
Sep 27, 2019
Messages
4
You can't export an Access file to CSV.
Do you mean export all the tables in each file to CSV?

BTW Welcome to AWF

Yes you are right. i have multiples files and i have to export the tables present in each file to CSV.

I do see a link in the response below - this material from ghudson.

But i guess this will export the tables from only one file. please correct me if i am wrong. Thanks for your response.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:40
Joined
Feb 19, 2002
Messages
43,272
The code as written runs within the database where the objects exist. You will need to create a new Access app. The app will read the .mdb's and .accdb's from all folders or a specific folder and by creating a database object that references an external database, you can run the code against each of the databases one at a time.

However, you need to give some thought to how the output will be organized. Are there duplicate databases? Surely there are common file names. So come up with a plan on how to organize the output and how automated you want the database selection to be.

I'm off to play bridge and have company tonight so there is no way I can help before Sunday. I do have code that could give you a start. It is used to document the tables of a specific database chosen by the user. You need a different method of choosing the database and the VBA needs to do the transfertext rather than build the table definition but I hope you can see how the code runs in dbA but works on tables in dbB which is what you need to get going.

Code:
Sub Create_tblTableFields()

''''Reference Field object definition https://msdn.microsoft.com/en-us/library/office/ff193203.aspx

    Dim db As DAO.Database
    Dim tblLoop As DAO.TableDef
    Dim fldLoop As DAO.Field
    Dim TD1 As DAO.TableDef
    Dim QD1 As DAO.QueryDef
    Dim TempSet1 As DAO.Recordset
    Dim strDatabase As String
    Dim ThisDB As DAO.Database
    Dim CountTables As Integer
    
   ''''On Error GoTo Create_tblTableFields_Error

  On Error GoTo Err_Create_tblTableFields
    'strDatabase = "C:\hartman\LinkDB2.mdb"
    strDatabase = Forms!frmPrintDoc!txtDBName
    
    CountTables = 0
    Set ThisDB = CurrentDb()
    If strDatabase = "" Then
        Set db = CurrentDb()
    Else
        Set db = DBEngine.Workspaces(0).OpenDatabase(strDatabase)
    End If
    
    db.Containers.Refresh
    
'''    Set QD1 = ThisDB.QueryDefs!QdeltblTableFields
'''        QD1.Execute
    Set TD1 = ThisDB.TableDefs!tblTableFields
    Set TempSet1 = TD1.OpenRecordset

    ' Loop through TableDefs collection.
    For Each tblLoop In db.TableDefs
        ' Enumerate Fields collection of each
        ' TableDef object.
        CountTables = CountTables + 1
        Forms!frmPrintDoc!txtTableCount = CountTables
        Forms!frmPrintDoc!txtTableName = tblLoop.Name
        Forms!frmPrintDoc.Repaint
                
        If Left(tblLoop.Name, 4) = "MSys" Or Left(tblLoop.Name, 2) = "xx" Or Left(tblLoop.Name, 2) = "zz" Or Left(tblLoop.Name, 1) = "~" Then
        Else
            For Each fldLoop In tblLoop.Fields
                TempSet1.AddNew
                TempSet1!TableName = tblLoop.Name
                TempSet1!FieldName = fldLoop.Name
                TempSet1!OrdinalPosition = fldLoop.OrdinalPosition
                TempSet1!AllowZeroLength = fldLoop.AllowZeroLength
                TempSet1!DefaultValue = fldLoop.DefaultValue
                TempSet1!Size = fldLoop.Size
                TempSet1!Required = fldLoop.Required
                TempSet1!Type = fldLoop.Type
                TempSet1!ValidationRule = fldLoop.ValidationRule
                TempSet1!Attributes = fldLoop.Attributes
                On Error Resume Next ' the following property is only available when it is not null
                TempSet1!Description = fldLoop.Properties("Description")
                TempSet1!FieldType = GetType(fldLoop.Type)
                TempSet1!Caption = fldLoop.Properties("Caption")
                If fldLoop.Attributes And dbAutoIncrField Then  'performs bitwise operation
                    TempSet1!AutoNum = True
                    TempSet1!Required = True
                Else
                    TempSet1!AutoNum = False
                End If
                TempSet1.Update
            Next fldLoop
        End If
    Next tblLoop

Exit_Create_tblTableFields:
    db.Close
    Exit Sub

Err_Create_tblTableFields:
    Select Case Err.Number
        Case 3043, 3055
            MsgBox "Please select a valid database.  Error #" & Err.Number, vbOKOnly
        Case 91   ' db was not opened so it cannot be closed.
            Exit Sub
        Case Else
            MsgBox Err.Number & " (" & Err.Description & ") in procedure Create_tblTableFields of Module DocumentCollections"
    End Select
    Resume Exit_Create_tblTableFields

   On Error GoTo 0
   Exit Sub
 

Mari

New member
Local time
Today, 10:40
Joined
Sep 27, 2019
Messages
4
Thanks for your help to help with the code. I have around 3500-4000 Access DB. I can put all these DB's in one folder. I have to loop through all the DB's to convert that into CSV file. I think that is not covered here. Will you able to help with that.

Thanks again.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:40
Joined
May 7, 2009
Messages
19,242
here you may try, I just made this.
if there were errors, please post back.
 

Attachments

  • External_db_to_csv.zip
    41.4 KB · Views: 145

Mari

New member
Local time
Today, 10:40
Joined
Sep 27, 2019
Messages
4
Thank you so much !!! It works perfect. You made my day.

Thanks everyone for the help
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:40
Joined
May 7, 2009
Messages
19,242
you're welcome!
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:40
Joined
Feb 19, 2002
Messages
43,272
Sounds like "spreadsheets" to me. That would be the only explanation.
 

Users who are viewing this thread

Top Bottom