import all modules

JPaulo

Developer
Local time
Today, 11:46
Joined
Dec 21, 2009
Messages
185
hi all;

Vba code, how to import all modules another mdb ?

Access 2003
 
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).
 
Hello friend.

I know this method, but now I want a vba cod, it is possible ?
 
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
 
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

Back
Top Bottom