What event happens when jumping from form to form?

Happy YN, I doubt that the event is not firing. HOWEVER there might be a question as to WHICH event is firing. As stated earlier, you ALWAYS need an event to be properly declared in order for your VBA code to be called.

Several ways exist to test this. All of them presume that you have GotFocus and Enter and Activate event code, which on a complex form could be tedious. However, there is a simple way to set this up.

First, in form design mode of form B, be sure that the properties [Events] panel is showing. Then select every control (and the form itself) and in the properties panel, double-click each of the GotFocus, Activate, and Enter slots so that it reads [Event procedure]. Do this for every control that does not already have a procedure defined. You might have to close the code window a lot during this exercise. What this will do is build an empty code scaffold in which you COULD put some stuff if you needed to do so. But you don't for the test I propose. You will probably also want to have the Form_Open, Form_Load, Form_Current events populated with these "stubs" if you had no code for those events before - and that is on TOP of the Enter, Activate, and GotFocus events. Now compile and save the VBA for that form. Save the form itself. Close it.

Next, you need to do something like set a breakpoint in some piece of code in your form A that is going to very soon do an Exit Sub or End Sub (thus releasing the control object and form A). For snorts and giggles, I'm going to presume that form B is launched by code in form A that does some variant of an Open Form command. If that is the case, the breakpoint goes on THAT Open command.

Your goal is to get into single-step mode at the same time that you will try to open form B. Single step past the Open and watch what entry points show up. (This is why you had to assure that you had events for everything.) When you open a form and the thing that opened it was in single-step mode, you STAY in single-step mode and will see the "Private Sub Giggle_Snort_Enter" header when you enter that routine, even if it does nothing but exit on the next step.

Note that this method WILL NOT WORK when you don't have code linked behind the event properties list entries. And that is why you double-clicked every event. The Event-Builder Wizard creates the entry point and return point scaffolding for you, and due to the specification for debugging in VBA, you WILL see the entry to that routine in single-step mode.
 
Hi,

Not sure if this thread is still relevant, but I have come across the same issue and thought I'd post how I overcame it.

I have FormA which has a button on it calling FormB

I have a colour change on the button calling FormB and want it to be reset when FormB is closed (Or any other actions)

I created a function in the code of FormA that reset the colour of the button

Function ResetColour
me.Command123.Forecolor = &HFFFF&
End Function

On FormB I call this function when the form is closed, (or in my case when the user presses the 'close form' button)

FormA.ResetColour

This then resets the colour (or will do any other actions when FormB is closed)

Thanks

Russ
 

Users who are viewing this thread

Back
Top Bottom