G
Guest
I have created a matrix of command buttons as shown in the code below. I have
a function with two parameters that are based on the command button name and
position in the matrix. When I call the ClickEventProc (ctl, intY) function,
it creates the Click procedure and the function call but then I get a window:
Run-time error '29054' Microsoft Office Access can't add, rename, or delete
the control(s) you requested.
Is there a way to assign a click function dynamically?
Woody
**Code that creates the controls:
For intY = 0 To intTotal
Set ctl = CreateControl("frm__test_form", acCommandButton)
ctl.Name = "ctl" & intY
ctl.Caption = varArray(intY)
ctl.Top = 1000 * (intY + 1)
ctl.Left = intLeftEdge
ctl.Height = 288
ctl.Width = 720
ctl.Visible = True
bCtl = ClickEventProc(ctl, intY)
Next intY
**Code that assigns a click procedure
Function ClickEventProc(ctl As Control, intY As Integer) As Boolean
Dim mdl As Module
Dim lngReturn As Long
Dim frm As Form
Set frm = Form_frm__test_form
Set mdl = frm.Module
lngReturn = mdl.CreateEventProc("Click", ctl.Name)
mdl.InsertLines lngReturn + 1, "findDisc(" & intY & "," & intY & ")"
ClickEventProc = True
End Function
**Resulting procedure with the "findDisc(0,0)" in red when the error window
comes up.
Private Sub ctl0_Click()
findDisc(0,0)
End Sub
a function with two parameters that are based on the command button name and
position in the matrix. When I call the ClickEventProc (ctl, intY) function,
it creates the Click procedure and the function call but then I get a window:
Run-time error '29054' Microsoft Office Access can't add, rename, or delete
the control(s) you requested.
Is there a way to assign a click function dynamically?
Woody
**Code that creates the controls:
For intY = 0 To intTotal
Set ctl = CreateControl("frm__test_form", acCommandButton)
ctl.Name = "ctl" & intY
ctl.Caption = varArray(intY)
ctl.Top = 1000 * (intY + 1)
ctl.Left = intLeftEdge
ctl.Height = 288
ctl.Width = 720
ctl.Visible = True
bCtl = ClickEventProc(ctl, intY)
Next intY
**Code that assigns a click procedure
Function ClickEventProc(ctl As Control, intY As Integer) As Boolean
Dim mdl As Module
Dim lngReturn As Long
Dim frm As Form
Set frm = Form_frm__test_form
Set mdl = frm.Module
lngReturn = mdl.CreateEventProc("Click", ctl.Name)
mdl.InsertLines lngReturn + 1, "findDisc(" & intY & "," & intY & ")"
ClickEventProc = True
End Function
**Resulting procedure with the "findDisc(0,0)" in red when the error window
comes up.
Private Sub ctl0_Click()
findDisc(0,0)
End Sub