Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy modules from one database to another via VBA

Status
Not open for further replies.

jane30

Programmer
Nov 14, 2000
92
0
0
US
Hi, in my Access 97 database, I have the following codes in module named "ModTest":

Dim db As Database, mod1 As Module, appcurr As Application
Set db = CurrentDb()
Set appcurr = Access.Application

For Each mod1 In appcurr.Modules
If mod1.name Like "ModFAC*" Then
docmd.copyobject "d:\db1.mdb","",acModule,mod1.name
else
MsgBox mod1.name
End If
Next

End Function

It returned me a message box "ModTest", which is not what I want to do.

I mean to check all the modules'names in my database. However, it seems that this script only checks the current open module. Is this caused by my definition of "appcurr", which is current Access.Application? What part of scripts is not right?

Much thanks in advance.
 
Hi Jane,

I created and tested below function just now. This will import modules from other dbs (make sure you specify correct db!).




Public Function CopyModuleOfOtherDB()

Dim db As DAO.Database, mod1 As Module
Dim rs As DAO.Recordset
Dim strPath As String

strPath = CurrentProject.Path & "\test1.mdb"
Set db = OpenDatabase(strPath, , True)

Set rs = db.OpenRecordset("SELECT * FROM MSysObjects WHERE TYPE=-32761")

With rs
Do While Not .EOF
Debug.Print .Fields("Name")
DoCmd.TransferDatabase acImport, "Microsoft Access", strPath, acModule, .Fields("name"), .Fields("name")
.MoveNext
Loop

End With

rs.Close
Set rs = Nothing
Set db = Nothing

End Function





Hope this helps... :)
Hasu
(Trust on someone, someone will trust you!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top