import all modules (1 Viewer)

JPaulo

Developer
Local time
Today, 17:18
Joined
Dec 21, 2009
Messages
185
hi all;

Vba code, how to import all modules another mdb ?

Access 2003
 

vbaInet

AWF VIP
Local time
Today, 17:18
Joined
Jan 22, 2010
Messages
26,374
Mr JPaulo again haha!

Just use the Import/Export tool in Access? Can be found in the toolbar in pre 2007, or on the ribbon (External Data tab).
 

JPaulo

Developer
Local time
Today, 17:18
Joined
Dec 21, 2009
Messages
185
Hello friend.

I know this method, but now I want a vba cod, it is possible ?
 

boblarson

Smeghead
Local time
Today, 09:18
Joined
Jan 12, 2001
Messages
32,059
Hello friend.

I know this method, but now I want a vba cod, it is possible ?

Here you go (you just need to pass the function the parameter which is the full database path and file name):

Code:
Function ImportAllModules(strDatabasePathAndName As String)
    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    Dim strSQL As String

    strSQL = "SELECT MSysObjects.Name, MSysObjects.Type " & _
             "FROM MSysObjects " & _
             "WHERE (((MSysObjects.Type)=-32761));"

    Set db = OpenDatabase(strDatabasePathAndName)

    Set rst = db.OpenRecordset(strSQL)

    Do Until rst.EOF
        DoCmd.TransferDatabase acImport, "Microsoft Access", strDatabasePathAndName, acModule, rst("Name"), rst("Name")
        rst.MoveNext
    Loop

    rst.Close
    Set rst = Nothing
    db.Close
    Set db = Nothing
End Function
 

boblarson

Smeghead
Local time
Today, 09:18
Joined
Jan 12, 2001
Messages
32,059
Oh and you should probably have error handling put in here and check to see if the module exists before doing the transfer and if so let the user change the name, or not do it.

This was only the basic code to get you started.
 

Users who are viewing this thread

Top Bottom