Link to home
Start Free TrialLog in
Avatar of Michael Paravicini
Michael ParaviciniFlag for Chile

asked on

Is there an Event to start processing when returning from another frame?

I have a split form where I would like the user to click on a button and a new frame opens where he can choose an existing client. This new client id is then returned to the calling frame. So far so good.

After this frame closes and a new Client ID has been received I need to insert a new record into the existing datasheet using the supplied client id. Unfortunately, I do not know how to kick off this processing once the CLIENT frame has been closed and the new client id has been stored in a variable on the frame? Any help which event I could/should use? Sorry if it sounds a bit confusing..

Thank you so much for your help! Regards Michael
Avatar of Fabrice Lambert
Fabrice Lambert
Flag of France image

Hi,

At the top of the calling form, declare a variable representing your client form, with the "WithEvents" keyword.
This way, the Calling will be aware of any events raised by the client form.

Sample code:
Option Explicit

Private WithEvents frmClient As Access.Form

Private Sub Button1_Click()
        '// instanciate and show the client form
    set frmClient = new Form_frmClient
    frmClient.show
End Sub

Private frmClient_Close()
    '// code to react to the OnClose event
End Sub

Open in new window

Another way is to take advantage of the Observer design pattern, as it induce less dependencies and finer control over variables's lifetime.
Avatar of Michael Paravicini

ASKER

Hi Fabrice  thank you so much for this very interesting solution. I have two questions: A) at the frmClient.Show statement I do get a runtime error 2465 Application Defined error and not sure why and the second, when I instancied the form with the Set frmClient = New Form_frmClient it will go to the Load event of the frmClient but it will genereate an error when I try to use the form "runtime error 2450 - cannot find the referenced form frmClient form.. Any clue why? Again, thank you so much for any help! Regards Michael
ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@mpim:
Can you upload your database so we can take a look ?
mpim Jim gave you the answer you need.

FYI,  What you are referring to as a frame is a form.  Knowing the names of objects will make it much easier to search for help.