DoCmd.CopyObject Error 2501

  • Thread starter Thread starter Cory
  • Start date Start date
C

Cory

I'm using Access 2007 on Vista.

I have a form with a command button that I use to view a second form. The
second form is always being programmatically modified so I have a default
form that I want to start with every time, copy it, then make the changes to
the form and open it. Here's the code I was using:


Private Sub cmd_Modify_Schedule_Click()
' Turn off warnings so the form is overwritten if it already exists
DoCmd.SetWarnings False
' Copy the default form to the Manpower Scheduling form
DoCmd.CopyObject , "frm_tmp_Scheduling_Manpower", acForm,
"frm_ZDefault"
DoCmd.SetWarnings True
' Make changes to the form here
DoCmd.OpenForm "frm_tmp_Scheduling_Manpower", , , , acFormReadOnly
End Sub

Everything worked fine until I locked the VBA project for viewing. When I
click the command button and the VBA project is locked I get a run-time error
(#2501) "The CopyObject action was canceled." If I unlock the project, it
runs as expected. I obviously would like to keep the project locked to
prevent anybody from tinkering with my code so any help would be greatly
appreciated. Thanks.

-Cory
 
Cory said:
I'm using Access 2007 on Vista.

I have a form with a command button that I use to view a second form. The
second form is always being programmatically modified so I have a default
form that I want to start with every time, copy it, then make the changes
to
the form and open it. Here's the code I was using:


Private Sub cmd_Modify_Schedule_Click()
' Turn off warnings so the form is overwritten if it already exists
DoCmd.SetWarnings False
' Copy the default form to the Manpower Scheduling form
DoCmd.CopyObject , "frm_tmp_Scheduling_Manpower", acForm,
"frm_ZDefault"
DoCmd.SetWarnings True
' Make changes to the form here
DoCmd.OpenForm "frm_tmp_Scheduling_Manpower", , , , acFormReadOnly
End Sub

Everything worked fine until I locked the VBA project for viewing. When I
click the command button and the VBA project is locked I get a run-time
error
(#2501) "The CopyObject action was canceled." If I unlock the project, it
runs as expected. I obviously would like to keep the project locked to
prevent anybody from tinkering with my code so any help would be greatly
appreciated. Thanks.


If that form contains any VBA code, I can understand why having the VBA
project locked would prevent copying it. Does it?

If it does, then my guess is that your best solution is to address your
programmatic modification of the form. What sorts of modifications are you
making at runtime? Can you either (a) prevent them from being saved when
the form is closed, or (b) restore the original attirbutes before the form
is closed?
 
The form that I am copying had an OnLoad event that was used to check if the
user had permission to view the form. I got rid of that code and everything
works again.

Just to clarify the root of the issue, I couldn't copy the form because I
was effectively trying to change the locked VBA Project as the form already
contained code?

Thanks for your help, it's greatly appreciated.

-Cory
 
Cory said:
The form that I am copying had an OnLoad event that was used to check if
the
user had permission to view the form. I got rid of that code and
everything
works again.

Just to clarify the root of the issue, I couldn't copy the form because I
was effectively trying to change the locked VBA Project as the form
already
contained code?

That was my theory, which your report seems to bear out.
Thanks for your help, it's greatly appreciated.

You're welcome.
 
Back
Top