Sub GetOtherDatabaseObjects(OtherDatabasePath As String, OtherDatabaseName As String, LikeClause As String)
Dim rstOtherDatabase As DAO.Recordset
Dim lngObjectType As Long
Dim sqlOtherDatabase As String
sqlOtherDatabase = "SELECT Name, Type FROM " & _
"[" & OtherDatabasePath & "\" & OtherDatabaseName & "].MSysObjects " & _
"WHERE Name Like '" & LikeClause & "';"
Set rstOtherDatabase = CurrentDb.OpenRecordset(sqlOtherDatabase)
Do
Select Case rstOtherDatabase.Fields("Type")
Case 1
lngObjectType = acTable
Case 5
lngObjectType = acQuery
Case -32768
lngObjectType = acForm
Case -32764
lngObjectType = acReport
Case -32761
lngObjectType = acModule
End Select
DoCmd.TransferDatabase acImport, "Microsoft Access", OtherDatabasePath & "\" & OtherDatabaseName, lngObjectType, rstOtherDatabase.Fields("Name"), rstOtherDatabase.Fields("Name")
rstOtherDatabase.MoveNext
Loop Until rstOtherDatabase.EOF
rstOtherDatabase.Close
Set rstOtherDatabase = Nothing
End Sub
Sub TestIt()
Call GetOtherDatabaseObjects("C:\", "db1.mdb", "##*")
End Sub