M
MDW
OK, I'm working on code that creates form controls on the
fly, and then deletes them once the form is closed
(because the next time that form is opened, you get
a "Control named xyz already exists"). I can get it to
create the controls OK, but for some reason I'm getting a
very odd error when I click the button to close the form.
Here's the error:
"The expression On Click you entered as the event property
setting produced the following errer:
- The expression may not be the name of a macro, user
defined function, or [Event Name]
- There was an error evaluating a macro, user defined
function, or [Event]
Here's the code behind the event button. It's sitting on a
form named "ControlAccess" -
Private Sub PRMcmdClose_Click()
Call removeBoxes
End Sub
The sub removeBoxes sits in a Global Module. Here's the
code -
Public Sub removeBoxes()
Dim objCtl As Control
DoCmd.Close acForm, "ControlAccess", acSaveNo
DoCmd.OpenForm "ControlAccess", acDesign, , , , acHidden
For Each objCtl In Application.Forms
("ControlAccess").Controls
If Left(objCtl.Name, 4) <> "PRMc" Then
DeleteControl "ControlAccess", objCtl.Name
End If
Next
' Save the form with the items deleted
DoCmd.Close acForm, "ControlAccess", acSaveYes
What's frustrating is that I HAVE gotten this to work. It
seems to bomb out after I delete a command button from a
third form. The sub that opens the form "ControlAccess"
uses the CreateControl method to create a checkbox
on "ControlAccess" for each command button on this third
form. I have it set up this way because the number of
command buttons could change in the future, and I want the
form "ControlAccess" to reflect the changes on this third
form (when I won't be around to program the thing).
fly, and then deletes them once the form is closed
(because the next time that form is opened, you get
a "Control named xyz already exists"). I can get it to
create the controls OK, but for some reason I'm getting a
very odd error when I click the button to close the form.
Here's the error:
"The expression On Click you entered as the event property
setting produced the following errer:
- The expression may not be the name of a macro, user
defined function, or [Event Name]
- There was an error evaluating a macro, user defined
function, or [Event]
Here's the code behind the event button. It's sitting on a
form named "ControlAccess" -
Private Sub PRMcmdClose_Click()
Call removeBoxes
End Sub
The sub removeBoxes sits in a Global Module. Here's the
code -
Public Sub removeBoxes()
Dim objCtl As Control
DoCmd.Close acForm, "ControlAccess", acSaveNo
DoCmd.OpenForm "ControlAccess", acDesign, , , , acHidden
For Each objCtl In Application.Forms
("ControlAccess").Controls
If Left(objCtl.Name, 4) <> "PRMc" Then
DeleteControl "ControlAccess", objCtl.Name
End If
Next
' Save the form with the items deleted
DoCmd.Close acForm, "ControlAccess", acSaveYes
What's frustrating is that I HAVE gotten this to work. It
seems to bomb out after I delete a command button from a
third form. The sub that opens the form "ControlAccess"
uses the CreateControl method to create a checkbox
on "ControlAccess" for each command button on this third
form. I have it set up this way because the number of
command buttons could change in the future, and I want the
form "ControlAccess" to reflect the changes on this third
form (when I won't be around to program the thing).