Exlude form in new DB copy

P

PJFry

My team uses a database that I periodically need to make changes to. There
is a development and production copy. The development copy contains a form
and coding so I can declare if the changes constitute and major, intermediate
or minor release. When the code on the form is excuted, a copy is made of
the development database that overwrites the production copy.

After this process is complete, I need to go into the new production copy
and remove the form I use to publish the database. If I forget to do this it
would be possible for someone to try an publish the production copy back to
itself.

Is there a way to remove the form out of the new database after it is
published as part of the copy process? It production copy is always in the
same place with the same name.

Thanks!

PJ
 
G

Graham Mandeno

Hi PJ

You cannot delete a Document from a Container using the Delete method, and
DoCmd.DeleteObject will only work on the current database, so the only way
to do this is to open the target database as the current database in another
instance of Access.

The function below should do the trick for you:

Call DeleteExternalObject( "path to your production copy",
acForm, "Name of form")
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

============= start code ==============
Public Function DeleteExternalObject( _
dbPath As String, _
ObjectType As AcObjectType, _
ObjectName As String) As Boolean
Dim acc As Access.Application
On Error GoTo ProcErr
Set acc = New Access.Application

With acc
'Temporarily set security to low to avoid warning
.AutomationSecurity = 1 ' msoAutomationSecurityLow
Call .OpenCurrentDatabase(dbPath, True)
.DoCmd.DeleteObject ObjectType, ObjectName
End With
DeleteExternalObject = True
ProcExit:
On Error Resume Next
If Not acc Is Nothing Then
acc.Quit acQuitSaveAll
Set acc = Nothing
End If
Exit Function
ProcErr:
MsgBox Err.Description, vbExclamation
Resume ProcExit
End Function
=========== end code ==============
 
M

Marshall Barton

PJFry said:
My team uses a database that I periodically need to make changes to. There
is a development and production copy. The development copy contains a form
and coding so I can declare if the changes constitute and major, intermediate
or minor release. When the code on the form is excuted, a copy is made of
the development database that overwrites the production copy.

After this process is complete, I need to go into the new production copy
and remove the form I use to publish the database. If I forget to do this it
would be possible for someone to try an publish the production copy back to
itself.

Is there a way to remove the form out of the new database after it is
published as part of the copy process? It production copy is always in the
same place with the same name.


If you can rely on the production copy being in a different
place than the development copy, you could hard code the
development path in the form's Open event and Cancel it
dosn't match. I.e. use CurrentProject.Path

A similar idea to to use a different name for the
development db and change the name when it is published.
Then use the form's open event to check matching name. I.e.
use CurrrentProject.Name

At least either of these ways the form doesn't need to be
deleted, but it will not open in a production copy.
 
P

PJFry

Good point. I'll try and incorporate that.
--
Regards,

PJ
Please rate this post using the vote buttons if it was helpful.
 
P

PJFry

Perfect. Thanks!
--
Regards,

PJ
Please rate this post using the vote buttons if it was helpful.



Graham Mandeno said:
Hi PJ

You cannot delete a Document from a Container using the Delete method, and
DoCmd.DeleteObject will only work on the current database, so the only way
to do this is to open the target database as the current database in another
instance of Access.

The function below should do the trick for you:

Call DeleteExternalObject( "path to your production copy",
acForm, "Name of form")
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

============= start code ==============
Public Function DeleteExternalObject( _
dbPath As String, _
ObjectType As AcObjectType, _
ObjectName As String) As Boolean
Dim acc As Access.Application
On Error GoTo ProcErr
Set acc = New Access.Application

With acc
'Temporarily set security to low to avoid warning
.AutomationSecurity = 1 ' msoAutomationSecurityLow
Call .OpenCurrentDatabase(dbPath, True)
.DoCmd.DeleteObject ObjectType, ObjectName
End With
DeleteExternalObject = True
ProcExit:
On Error Resume Next
If Not acc Is Nothing Then
acc.Quit acQuitSaveAll
Set acc = Nothing
End If
Exit Function
ProcErr:
MsgBox Err.Description, vbExclamation
Resume ProcExit
End Function
=========== end code ==============

PJFry said:
My team uses a database that I periodically need to make changes to.
There
is a development and production copy. The development copy contains a
form
and coding so I can declare if the changes constitute and major,
intermediate
or minor release. When the code on the form is excuted, a copy is made of
the development database that overwrites the production copy.

After this process is complete, I need to go into the new production copy
and remove the form I use to publish the database. If I forget to do this
it
would be possible for someone to try an publish the production copy back
to
itself.

Is there a way to remove the form out of the new database after it is
published as part of the copy process? It production copy is always in
the
same place with the same name.

Thanks!

PJ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top