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!

Delete object in other database

Status
Not open for further replies.

NormDuffy

Programmer
Jul 9, 2001
18
0
0
FR
I need to copy several objects to other databases.

I have managed to do this but experience errors if the object already exists.

The code below is a modified sample from Microsoft and it works, in that it deletes the object before the copy but it uses the OpenCurrentDatabase method to do this. This causes code to run in databases where there are autoexec macros or forms with code etc which run on open.

I need to know if there is someway to do this using the OpenDatabase method so the code in the other database is not activated.

Public Function TransferObject(Filename As String, _
objType As Integer, objName As String)

On Error Resume Next

Dim accObj As New Access.Application
accObj.OpenCurrentDatabase Filename
accObj.DoCmd.DeleteObject objType, objName
accObj.CloseCurrentDatabase
Set accObj = Nothing
DoCmd.TransferDatabase acExport, _
"Microsoft Access", Filename, objType, objName, _
objName, False

End Function
 
Well, if it's DAO....

Dim DBSremote as database
Set DBSremote = "Path and filename to remote database"

My web page has an example. Go to the code examples and use ctl+f to search for Copying a Module to multiple databases.

Tyrone Lumley
augerinn@gte.net
 
I would look into useing DAO 3.6 instead of the DoCmd

Read up on collections in the Help file and how to add and remove objects from the database collection

You will have to add Microsoft DAO 3.6 in from references
 
Hi Guys
Thanks for the feedback but perhaps I should explain a little more of what I was doing. The following code was my original code which works great if the objects are modules tables etc but Access97 has problems if you tray and copy a form that already exists. It generates an error and closes the database. This is documented on the Microsoft site and that is where the previous modified code came from. I need to delete a form in the other database prior to the attemt to copy it to overcome this access bug.
The original code follow. Works fine but not with forms.

Function UpdateAllCommonDatabases()

Dim dbsThisDatabase As DataBase
Dim rstTheseDatabases As Recordset, rstTheseObjects As Recordset
Dim txtOtherDatabase As String

Set dbsThisDatabase = CurrentDb
Set rstTheseDatabases = dbsThisDatabase.OpenRecordset("tblBootUser", dbOpenDynaset)
Set rstTheseObjects = dbsThisDatabase.OpenRecordset("tblObjectsToCopy", dbOpenDynaset)

rstTheseDatabases.MoveFirst

Do While Not rstTheseDatabases.EOF
txtOtherDatabase = rstTheseDatabases!PathMDB & "\" & rstTheseDatabases!DatabaseName & ".MDB"
If rstTheseDatabases!Managed = True Then
rstTheseObjects.MoveFirst

Do While Not rstTheseObjects.EOF
DoCmd.TransferDatabase acExport, "Microsoft Access", txtOtherDatabase, _
rstTheseObjects!objecttype, rstTheseObjects!objectname, rstTheseObjects!objectname
rstTheseObjects.MoveNext
Loop

Else

End If

rstTheseDatabases.MoveNext
Loop

End Function

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top