
Creating Event Procedures Automatically
What's wrong with the function below?
I get a Runtime error '57017' Event hander is invalid
The line that is highlighted in yellow is:
lngReturn = mdl.CreateEventProc("Unload", mdl.Name)
I have also tried:
lngReturn = mdl.CreateEventProc("Unload", frm.Name)
The only line like this that actaully executes fine is:
lngReturn = mdl.CreateEventProc("Click", ctl.Name)
Function AutoCode()
Dim frm As Form, ctl As Control, mdl As Module, lngReturn As Long
Set frm = CreateForm
Set ctl = CreateControl(frm.Name, acCommandButton, , , , 1000, 1000)
ctl.Caption = "Click here"
Set mdl = frm.Module
lngReturn = mdl.CreateEventProc("Click", ctl.Name)
mdl.InsertLines lngReturn + 1, vbTab & "MsgBox ""Test"""
lngReturn = mdl.CreateEventProc("Unload", mdl.Name)
mdl.InsertLines lngReturn + 1, vbTab & "MsgBox ""Unload?"""
End Function