TomPythonHelp
TomPythonHelp

Reputation: 31

Dynamically export tables in MS Access to CSV

I'm wondering is it possible to dynamically export specific MS Access tables to a CSV file using VBA?

I'm able to export all the tables to a CSV / Excel file but the ask I was given once this was in place, is to be able to export a specific set of tables from the MS Access database a CSV file and not the entire set of tables.

Ideally the user would access a Form which they'd be able to select the tables they would like to export and click a button that would run the script.

Is this possible using VBA or is it to complex? Any advice or resources would be appreciated. Thanks!

Upvotes: 0

Views: 169

Answers (1)

hennep
hennep

Reputation: 660

You can use this query to populate your listbox:

SELECT MSysObjects.Name
FROM MSysObjects
WHERE ((Left([Name],4)<>"~TMP" And Left([Name],4)<>"MSys" And Left([Name],2)<>"f_") AND ((MSysObjects.Type)=1));

To list the tables in VBA:

Public Sub enum_tables()
    Dim td As TableDef
    For Each td In CurrentDb.TableDefs
        If Left(td.Name, 4) <> "MSys" And Left(td.Name, 4) <> "~TMP"  Then
           Debug.Print td.Name
        End If
    Next
End Sub

The matches between the selection in the listbox and the list from 'enum_tables', are the ones you want to export

Upvotes: 1

Related Questions