Catching a custom form event in another instance

G

Guest

Hi,

I have this form I use to look for contacts and it uses the following event:

Public Event ContactSelected(nCNT_ID As Integer)

Whenever a contact is selected the following code is ran to raise the event
and pass the ID of the selected contact:

RaiseEvent ContactSelected(CNT_ID.Value)

On my calling form I declare a form like:

Public WithEvents frmSearch As Form

To try and catch the event this form raises I use something like:
DoCmd.OpenForm("Search")
Set frmSearch = Forms("Search")

I am also using a sub to try and catch the event but this doesn't seem to
ever get called even though I do raise the event.

Public Sub frmSearch_ContactSelected(nCNT_ID As Integer)
Me.nCNT_ID = nCNT_ID
MsgBox "Found: " & nCNT_ID
End Sub

Please does anyone know how to catch a form's custom event?
 
A

Alex Dybenko

Hi,
i think you have instantiate a form using its class:

dim frmSearch as Form_Search

set frmSearch = new Form_Search
frmSearch.visible=true

Also you can try to use form's open event (but i am not sure)
Set frmSearch = Form_Search
 
G

Guest

Thank you very much, you are right

After trying a few things out yesterday I noticed that I could get a typed
reference to my forms too which did indeed expose the custom event handler.

So to recap:

Declaration:
Private WithEvents frmZoeken As Form_SearchContact

To get a reference:
DoCmd.OpenForm ("SearchContact")
Set frmSearch = Forms("SearchContact")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top