C
chammock
I have a form, and when I close it I need to delete some controls off
the form. I have the deletion process working fine on a Test form when
I call the Cleanup function from a Command Button. It just opens the
form in acDesign mode, cleans it up and then saves it. But when I try
to call the Cleanup function from the Form itself on Close I keep
getting errors. My understanding is that I need to go from acNormal to
acDesign mode to delete the controls, but when I try to switch the
current form from acNormal to acDesign on the Close event of that form,
I get errors.
Thanks for any help you can provide. Let me know if you need more
clarification.
Here is some of the code, which works when I call it from a test form
using a command button, but not when I call it from the Form I need to
cleanup on its close event.
====================
Public Function CleanupTemplate(TemplateName As String)
Dim varControl As Variant
Dim varModule As Variant
Dim db As Database
Dim cnt As Container
Dim doc As Document
Dim frm As Form
Dim mdl As Module
Dim str As String
Dim i As Integer
Dim strTemplateName As String
strTemplateName = TemplateName
MsgBox (strTemplateName)
'Open the form in design mode and hidden
DoCmd.SetWarnings False
DoCmd.OpenForm TemplateName, acDesign, , , , acHidden
For i = Forms(TemplateName).Controls.Count - 1 To 0 Step -1
Set varControl = Forms(TemplateName).Controls(i)
'MsgBox (varControl.Name)
If Mid(varControl.Name, 1, 6) = "vbacmd" Then
DeleteControl TemplateName, varControl.Name
End If
Next
DoCmd.Save
the form. I have the deletion process working fine on a Test form when
I call the Cleanup function from a Command Button. It just opens the
form in acDesign mode, cleans it up and then saves it. But when I try
to call the Cleanup function from the Form itself on Close I keep
getting errors. My understanding is that I need to go from acNormal to
acDesign mode to delete the controls, but when I try to switch the
current form from acNormal to acDesign on the Close event of that form,
I get errors.
Thanks for any help you can provide. Let me know if you need more
clarification.
Here is some of the code, which works when I call it from a test form
using a command button, but not when I call it from the Form I need to
cleanup on its close event.
====================
Public Function CleanupTemplate(TemplateName As String)
Dim varControl As Variant
Dim varModule As Variant
Dim db As Database
Dim cnt As Container
Dim doc As Document
Dim frm As Form
Dim mdl As Module
Dim str As String
Dim i As Integer
Dim strTemplateName As String
strTemplateName = TemplateName
MsgBox (strTemplateName)
'Open the form in design mode and hidden
DoCmd.SetWarnings False
DoCmd.OpenForm TemplateName, acDesign, , , , acHidden
For i = Forms(TemplateName).Controls.Count - 1 To 0 Step -1
Set varControl = Forms(TemplateName).Controls(i)
'MsgBox (varControl.Name)
If Mid(varControl.Name, 1, 6) = "vbacmd" Then
DeleteControl TemplateName, varControl.Name
End If
Next
DoCmd.Save