Full Version: Navigation bewteen forms, events that fire
UtterAccess Forums > Microsoft® Access > Access Forms
Hi all,
I have two unbound forms that I am navigating between. I open the first form, then open the second form from a command button on the first form. When I am finished with entry on the second, my close button on the second form updates a combo box (ComboBox1) on the first form with the proper value.
The issue that I am having is that I'm also trying to update some textboxes on the first form after the update of the combo box on the first form. Currently, I have functions and subs that update these textboxes after ComboBox1 AfterUpdate event occurs. This works fine when I am on the first form and update ComboBox1.
I would like the same processes to happen after the second form closes and ComboBox1 is updated, but I have yet to figure out how to fire an event on the first form after the second form is closed. It seems once the second form closes, no OnCurrent, Activate, or GotFocus event occurs on the first form where I could insert the calls to the procedures that I want to do.
Any suggestions or perhaps insight would be appreciated!
will give you the events and when they happen.
The On_Activate on the first form is where I would try first.
Thanks Glen - I've found some similiar info in the help section. As I mentioned in the first post, I've tried OnCurrent, Active, GotFocus - nothing seems to be firing, my only guess is that it is because I am not moving between forms using the mouse. Instead, the following happens:
econd form - click on command to close form, Close form event happens
Code in close form event (where frm is set to the first form):
frm.ComboBox1= hiddenVal
DoCmd.Close acForm, Me.Form.Name, acSaveNo
DoCmd.SelectObject acForm, frm.Name
After this, the second form is closed and the first form is the active form, but no events on the first form are firing. I am trying to fire an event on the first form so I can call some procedures which update the textboxes on the first form.
Try switching these two lines around:
oCmd.Close acForm, Me.Form.Name, acSaveNo
DoCmd.SelectObject acForm, frm.Name
DoCmd.SelectObject acForm, frm.Name
DoCmd.Close acForm, Me.Form.Name, acSaveNo
I tried that, set some breaks on the first form's Form_Activate, Form_Current, and Form_GotFocus parts of the code, and not one of these fired once the second form was closed. Should one of these fire?
Yes one should fire.
tried a test and here is what I did I created 2 forms. Nothing on them just 2 forms.
Code for Form1:
Private Sub Form_GotFocus()
MsgBox "I am back "
End Sub
Private Sub Form_Load()
DoCmd.OpenForm "Form2"
End Sub
Code for Form2
Private Sub Form_Unload(Cancel As Integer)
DoCmd.SelectObject acForm, "Form1"
End Sub
When I open Form1 I see the message box, when I close Form2 I see the message box telling me the event fires.
Now without actually seeing your database itis hard to tell what you need to do. You may have to set a control to get focus or create a control to set the focus to first then run your code from there.
Here is a little demo of what I am talking about hope it helps in some small way. See Attached
Thanks for the example, Glen. I've included an example of how my code works - and the msgbox does not fire. I think the differences are as follows:
I don't let the user close the form from the red "X" close item at the top of the form. I disable these form properties because I prefer to have the user always get into a habit of using the command buttons
- I use a command button to close the form and update the other form's textbox and close the current form
- I don't use the Unload event on the second form, just the command button click event
Perhaps I am coding myself into a corner, but I'm hoping that there is an event that would fire with the methods I am using.
Thanks for all your help!
See my revision to your sample.
I have placed another text box on the form it looks like a 1 under the first textbox label.
You can size it smaller so it won't even be seen but I left it so you could see it. I use the Got Focus of this control to run my message box also check out form 2 code.
Without seeing the actual database this is the best I can suggest. Use a control to run your needed code.
That was it! For some reason I was focused on the form, not the control.
any thanks Glen.
Glad I could help.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.