Events on tab controls (1 Viewer)

MayoM

New member
Local time
Today, 10:06
Joined
Nov 9, 2012
Messages
4
Who has got a good grasp of events on tab controls?​

Up to a recent set of tests the tabControl_Click event handling was working perfectly. Now I discover that there is one sequence of events where the click event does not fire up as I expect.

The sequence of events is:

Based on a subform within the main form, I make the tabs visible and show pag0
Me.Parent!tabControl.Visible = True
Me.Parent!tabControl.Pages("pag0").SetFocus

pag0 displays a form. I update something. I click the tab for pag1.

The BeforeUpdate event for the form on pag0 kicks in. I send out a MsgBox to confirm that the update is wanted. For safety I set Cancel = False. The update to the table goes through OK.

pag1 displays its forms OK. Everything is fine up till now, but the tabControl_Click event does not get triggered.

If I click the tab for pag1 again, the tabControl_Click event gets triggered OK.​

So am I expecting too much for the tab controls to trigger both an update on the old tab and to trigger some code on the new tab?

How do I debug what is going on? I cannot see how I delve into something which isn't happeneing.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:06
Joined
Feb 19, 2002
Messages
43,263
The popup of the message box may be causing the disruption. Comment out that line of code to verify.
 

MayoM

New member
Local time
Today, 10:06
Joined
Nov 9, 2012
Messages
4
Pat

You are quite right.

When the MsgBox statement is commented out, the tabControl_click event gets triggered correctly.

So what options do I have? A message is needed to be consistent with other part of the ap. Other threads have suggested the use of the change event rather than the click event. I am a bit wary because I have not found a detailed write-up of the differences between the two events.

I am using Access 2010.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:06
Joined
Feb 19, 2002
Messages
43,263
The Change event fires for EVERY character typed in a control so it is only useful if you are trying to trap keystrokes. The click event fires once when the mouse is clicked in the control. So, the Change event would nnot solve your problem.

If the click event fires before the BeforeUpdate event for the form you are leaving (add message boxes to each event so you can determine the order), you can save the tab page in a variable and then in the AfterUpdate event, you can look at the tab page variable and if it has a value, clear it and call the click event for that tab page to force it to fire. You will need to clear this variable in the Current event of the form.
 

MayoM

New member
Local time
Today, 10:06
Joined
Nov 9, 2012
Messages
4
Pat, many thanks for the response.

With a tabControl and the change event, key strokes do not really apply. So would I be correct in interpreting it to mean that it gets triggered when the value of the tabControl changes?

Concerning your coding suggestion, the BeforeUpdate event fires while the page I am leaving is still displayed and with the value of the tabControl still relating to the page which is displayed. So the catch is that I do not know which tab was clicked unless the Click event fires up.

Despite your warning I have gone ahead with Change event approach. In my situation this looks OK in that:

(a) My original problem does not occur. I can trigger both a BeforeUpdate event on the old tab and trigger a Change event on the new tab.

(b) If I have code for both the Click event and the Change event, only one ever fires up. The Change event fires up when I click on a new tab and the Click event fires up when I click on the current tab. So I will be removing the Click event.

So problem solved - until something else crops up!

Again many thanks Pat.
 

Users who are viewing this thread

Top Bottom