Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with CreateEventProc

Status
Not open for further replies.

aliendan

Programmer
Jun 28, 2000
79
US
OK, I'm gonna start screaming pretty soon now. This is driving me up a wall. There's something I'm not seeing here that I'm hoping somebody else will see and help me out here.

After I've programmatically created a form I want to insert code into the Form Open event and I keep getting this error:

Run-time error '57017'
Event handler is invalid

The code is:

Dim mdl As Module, lngReturn As Long, frm As Form

Set mdl = frm.Module
lngReturn = mdl.CreateEventProc("Open", frm.Name)
mdl.InsertLines lngReturn + 1, vbTab & "Call FrmOpn"

FrmOpn is a Public Function.

Can anyone see anything wrong here?
Dan Rogotzke
Dan_Rogotzke@oxy.com
 
After looking at this on a new day with a clear mind I figured it out. When you create a form with syntax like this:

Set frm = CreateForm()

You get a form with the name Form1. So now if you look in the VB editor in the Object list there is no Form1. There is a Form listed there. So if you want to insert a procedure in the Open event you can't use the frm.Name because it looks for an Object called Form1. This is what you have to use:

Dim mdl As Module, lngReturn As Long, frm As Form

Set mdl = frm.Module
lngReturn = mdl.CreateEventProc("Open", ("Form"))
mdl.InsertLines lngReturn + 1, vbTab & "Call FrmOpn"

This tells it to find the Object called Form, which does exist in the Object list for all forms.

Sometimes it's amazing what a new day can bring you.

Dan
Dan Rogotzke
Dan_Rogotzke@oxy.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top