Microsoft KB Archive/238312

= How To Fire TabStrip's Click Event When Using Msgbox in BeforeClick =

Article ID: 238312

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q238312



SUMMARY
If a message box is displayed in a TabStrip control's BeforeClick event handler, the TabStrip control's Click event handler will not be fired, even if the Cancel parameter is set to False. In some situations it may be necessary to validate the information in the BeforeClick event handler and then display a message box to determine if the user wishes to continue. If so, the Click event should be fired.



MORE INFORMATION
The optimum workaround depends upon the situation:

Situation 1:
If you don't need to reference the TabStrip1.SelectedItem.Index property in the Click event handler, you can call the function directly. For example: Private Sub TabStrip1_BeforeClick(Cancel As Integer) If MsgBox("Do you want to continue?", vbYesNo) = vbYes Then TabStrip1_Click Else Cancel = True End If End Sub

Private Sub TabStrip1_Click MsgBox "click event handler is called" End Sub

Situation 2:
If the Click event handler is called inside the BeforeClick event, the index value has not yet been changed. So if you must reference the TabStrip1.SelectedItem.Index property, you must call the Click event after exiting the BeforeClick event. One solution is to use a Timer control. For example: Option Explicit

Private Sub Form_Load TabStrip1.Tabs(1).Selected = True Timer1.Interval = 1 Timer1.Enabled = False End Sub

Private Sub TabStrip1_BeforeClick(Cancel As Integer) If MsgBox("Do you want to continue?", vbYesNo) = vbYes Then Timer1.Enabled = True 'call the click handler Else Cancel = True End If End Sub

Private Sub TabStrip1_Click msgbox "Change to tab " & TabStrip1.SelectedItem.Index End Sub

Private Sub Timer1_Timer Timer1.Enabled = False TabStrip1_Click 'call it here End Sub

