Is there an 'On Exit' even when switching between tabs?

WinDancer

Registered User.
Local time
Today, 13:30
Joined
Oct 29, 2004
Messages
290
I want to fire a routine when the user leaves a specific tab on my form. Is there an 'On Exit' even for form tabs?

Thanks,
Dave
 
A quick look seems to indicate no. It also makes sense, because tab controls or pages seldom, if ever, have the focus. Only textboxes, listboxes, comboboxes, option groups, and a handful of other controls can receive and lose focus and thus have Enter and Exit event.

If this is really important, you could put it in a subform and use the control's exit event to simulate the leaving the event, but I'm pretty sure it may be unreliable. Another solution that's a bit more robust is to use form's close event, so if you created, for instance, a pop up form, you can enforce that the form's close event is required to be fired whenever the user is done with it.
 
Couldn't you use the OnClick event? When you click on "Tab2" you are exiting "Tab1".
 
Tried that- it works ONLY if you click down in the meaty area on the form- not on just the tab.
I have combined it with another process, but it is clunky running from there.

I am NEVER going to use tabbed forms again- there are just too many work-arounds required.

Thanks,
Dave
 
you could probably store the active tab, and then see if the control you go to is on the same tab - if not react accordingly

there must be a suitable container object, or a control parent to indicate the tab sheet, owning a given control
 
WinDancer,

Actually, you should use OnChange event of the Tab Control; whenever the tab is clicked (e.g. moved to another tab), that event will fire every time.
 
There are only four options for tab events-
On Click
On Double Click
On Mouse Down
On Mouse Up
On Mouse Move
There is no
OnChange
On Enter

Thanks,
Dave
 
You listed events for *pages*, not tab control, which contains pages.

To make sure you're referencing the tab control, click the grey area to right of tabs, not inside or select it from property windows, which is named by default "TabCtlXX" where XX is a number
 
You are correct- I was able to locate the OnChange event for the TabControl.

I have 4 tabs on my form- The event needed to happen when they left page3 and no other time.

Is there a way to limit the event to only leaving that page?

Thanks,
Dave
 
Yes:

in the OnChange event, check for tab control's value and see if it's equal to pageindex property of the page 3 (if you built pages in order, it would typically be 2).

If you use tabs or buttons options (rather than none), the OnChange event fires after the tab has changed (e.g. after leaving the page), so you will have to have a check to verify if the last tab visited was page 3 and do something.

HTH.
 
I can't figure it out-
Here is what I have been working with so far...

Private Sub TabCtl0_Change()
Dim ctlPrevious As Control
Set ctlPrevious = screem.PreviousControl
If ctlPrevious.Name = "page3" Then
MsgBox "Oh Heck!"
End If
End Sub

Thanks,
Dave
 
PreviousControl (and Screen object as well) are unreliable and doesn't always behave as you would expect it to.

A possible solution:

Code:
Public bHere as Boolean

Private Sub TabCtl10_Change()

If TabCtl10 = 2 Then 'I'm just guessing here that pageindex of page 3 is 2. Verify.
   bHere=True
Else
   If bHere Then
      Msgbox "Oh Heck"
   End If
End If

End Sub

Note: I didn't set bHere false anywhere; you will need to set it to False when users are allowed to leave page 3.
 
OK- here is where I am right this minute:

Public bHere As Boolean


Private Sub TabCtl0_Change()


If TabCtl10 = 2 Then 'I'm just guessing here that pageindex of page 3 is 2. Verify.
bHere = True
MsgBox "Option1: It Works!"
Else
If bHere Then
MsgBox "Option2: Oh Heck"
End If
End If
MsgBox "Option3: Nothing read..."
End Sub

The last msgbox is the only one that fires, regardless of which tab you move from

Thanks,
Dave
 
I also stumbled across the OldValue command and tried that:

Private Sub TabCtl0_Change()


If TabCtl10.OldValue = 2 Then
MsgBox "You were on page3"
End If
MsgBox "Option2: Oh Heck"

End Sub

but it is giving me an object required error...
 
Did you verify that page 3's pageindex is in fact 2?
 
In my post 11 the control is Ctl0
In post 12, which I copied to try, the control name is Ctl10
I will go back tomorrow and try some of the suggestions using the correct name :(
I HATE when I do dumb stuff like this!
Thanks to all for the help...
Dave
 
They both appear to work, but on change means there is not yet a value for old value or previous value...
 

Users who are viewing this thread

Back
Top Bottom