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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code To import/delete objects based upon name patterns

Status
Not open for further replies.

BryanHec

Programmer
Jul 6, 2006
9
US
I need a piece of code that allow me to copy(Imports) objecgts from one database into another. I do not want all the objects, just some that follow certain name conventions, for example starts with 2 digit numbers like "01 test query". Also, could I do the same if I need to delete objects from the database?

Thank you
 
BryanHec,
Something like this?
Code:
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

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top