Can't Trigger Event Procedure from a Checkbox created on the Fly.

J

JGeniti

I'm creating a checkbox on the fly in a form. I know that the checkbox
name will be CkBox1 so I already created the following event procedure.
For some reason I can't get the event procedure to trigger when I click
on the checkbox that was created. I'm sure that it has something to do
with the fact that I'm creating procedure before the control is
created, but I would imagine there has to be a way. And due to the fact
that this form needs to be very dynamic, I can't really get away with
just creating the controls and hiding/unhiding them.
Any suggestions would be appreciated.

Thanks,
James

Private Sub CkBox1_Change()
If PackageForm.Controls("CkBox1").Value = True Then
With PackageForm.Controls("TBox4")
.Enabled = True
.Locked = False
.BackStyle = fmBackStyleOpaque
End With
Else
With PackageForm.Controls("TBox4")
.Enabled = False
.Locked = True
.BackStyle = fmBackStyleTransparent
.Value = ""
End With
End If
End Sub
 
J

JGeniti

JGeniti said:
I'm creating a checkbox on the fly in a form. I know that the checkbox
name will be CkBox1 so I already created the following event procedure.
For some reason I can't get the event procedure to trigger when I click
on the checkbox that was created. I'm sure that it has something to do
with the fact that I'm creating procedure before the control is
created, but I would imagine there has to be a way. And due to the fact
that this form needs to be very dynamic, I can't really get away with
just creating the controls and hiding/unhiding them.
Any suggestions would be appreciated.

Thanks,
James

Private Sub CkBox1_Change()
If PackageForm.Controls("CkBox1").Value = True Then
With PackageForm.Controls("TBox4")
.Enabled = True
.Locked = False
.BackStyle = fmBackStyleOpaque
End With
Else
With PackageForm.Controls("TBox4")
.Enabled = False
.Locked = True
.BackStyle = fmBackStyleTransparent
.Value = ""
End With
End If
End Sub
 

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