form custom event

Arti

New member
Local time
Today, 16:01
Joined
Mar 28, 2018
Messages
3
Hello!

Does anybody knows if it is possible to use a custom event declared with key word "Public Event" in a form class module?

I have two forms, the first named "frmListener" with one button "btnFrmListener", and the second one named "frmTrigger" with one button "btnFrmTrigger" and a custom public event "DoSomething".

On module of Form "frmListener" I have the following code:

Private WithEvents frm As Form

Private Sub btnFrmListener_Click()
DoCmd.OpenForm "frmTrigger"
Set frm = Forms("frmTrigger")
End Sub

'custom event of Form "frmTrigger"
Private Sub frm_DoSomething()
MsgBox "Done it!", vbOKOnly + vbInformation
End Sub

On module of Form "frmTrigger" I have the following code:

Public Event DoSomething()

Private Sub btnFrmTrigger_Click()
RaiseEvent DoSomething
End Sub


I first open "frmListener", click on button "btnFrmListener" to open Form "frmTrigger". Then I click on button "btnFrmTrigger" to raise event DoSomething but nothing happens! The event is not "catched" by "frm_DoSomething".

Can somebody help me?

Thank you
Arti
 
See this tutorial from Steve Bishop.
There are other related videos in his series. Number 52 may be more directly related to your post.
Good luck. It would be useful to others if you post your code when you get it working.
 
Last edited:
Thank you Jdraw for your suggestion. I had already checked Steven Bishop's tutorial on custom events. It is a great tutorial but I could not find the answer to my problem.

However, I found the solution and I have to say that it is very very easy!

It is enoug to declare the variable pointing to the Form with the name of the Form containing the custom event.

In my case: Private WithEvents frm As frmTrigger (As frmTrigger and not As Form).

Now it works!
 

Users who are viewing this thread

Back
Top Bottom