Creating Event Procedures Automatically 
Author Message
 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



Mon, 04 Jul 2005 00:58:38 GMT  
 Creating Event Procedures Automatically

Try this:

Public 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", "Form")
    mdl.InsertLines lngReturn + 1, vbTab & "MsgBox ""Unload?"""
End Function

---
Serge Gavrilov

Quote:

> 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



Mon, 04 Jul 2005 06:16:52 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Class Module - Cannot create an event procedure for control on form

2. how to write procedure that creates another procedure?

3. ASAP: How do u set the cmdOK_Click event to have more than one event procedure

4. hide code window and start procedure automatically

5. Freeware to automatically generate stored procedures

6. Inserting code into procedures - automatically

7. Inserting code into procedures - automatically

8. Inserting code into procedures - automatically

9. Addini events to a calender automatically

10. Automatically send a reminder email for a calendared event

11. Way to fire event ItemAdd automatically?

12. running a click event automatically

 

 
Powered by phpBB® Forum Software