Make a new event for a form?

How to make a new event for a form something like what can be done in an ActiveX control: declare an event, raiseevent.....
learnAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SicilianCommented:
Hi learn
   Couldn't you just declare your event in a class, Implement it in any form you want to use it in by declaring the class module with the WithEvents keyword, raise it appropriately and write code to the event?
    Perhaps you have no way of raising it appropriately? Maybe if you told us what the new event you want to implement is?

Sicilian
0
AnswerTheManCommented:
1. start a new project
2. add 2 forms (Form1, Form2)
3. paste this code to Form1 :
Option Explicit

Private WithEvents frmTest As Form2
Private Sub Form_Load()
    Set frmTest = New Form2
    Unload Form2
    Set Form2 = Nothing
    frmTest.Show
End Sub

Private Sub frmTest_OPS(str As String)
    MsgBox "There was a click in form2"
End Sub

4. paste this code to form2 :
Option Explicit

Public Event OPS(str As String)

Private Sub Form_Click()
    RaiseEvent OPS("click")
End Sub

5. run the project
6. click on form2
7. the event raised from form2 to form1, form1 displays a MsgBox about that.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
learnAuthor Commented:
To Sicilian:

Thank you.

Instesd a class I need a form which has got a "paper" to draw something :-)
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

learnAuthor Commented:
To  AnswerTheMan:

Your answer looks like what I need :-), but

1. You mens we can not create an event and list it in the event list of the form so that a user can code somthing into it in design time?

2. Why
   Unload Form2
   Set Form2 = Nothing
Form2 was loaded in your code?
0
AnswerTheManCommented:
1. you have not noticed well.
   look at Form1 Up menu and you'll see
   that there is an Object called
   'frmTest' there with all other controls. click on it, and on the right
   list you'll get it's public events
   which are the OPS event.
2. that is just a precaution. after you
   obtain a Refernce to Form2 by frmTest
   , you don't need FOrm2 anymore.
   in this example it may seems not in
   place, but in other cases it is
   recomended. making a habit to do it
   (won't raise any error here), is a
   good for preventing future bugs.
3. don't forget to unload and set nothing 'frmTest' on Form1_Unload event.
0
learnAuthor Commented:
Hi AnswerTheMan,

That is great! Thank you very much for your excellent answer and comment.
0
AnswerTheManCommented:
you welcome
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.