Hi,

Apologies if I'm missing something really easy here:

I have a TabStrip with 4 tabs on my form. When the user is editing the information on one of the tabs I want to display a message box confirming whether the data should be saved. Here is what I have:

Private Sub tabMainForm_Click(PreviousTab As Integer)
    If editing Then
        If MsgBox("Save changes?", vbYesNoCancel, applicationTitle) = vbYes Then
            cmdSave_Click (tabMainForm.Tab)
        End If
    End If
    If tabMainForm.Tab = 1 Then
        staffRst.Fields("BI") = CalculateBI
        staffRst.Update
        txtBI.Text = staffRst.Fields("BI")
    End If
End Sub

The program will switch to the new tab before displaying the message. Is there any way I can show the message box first then decide whether to switch tabs?

Thanks in advance,

Andy.

Try the change event, if there's an cancel property on their parameter then use it. or maybe the mousedown event.

I have a TabStrip with 4 tabs on my form. When the user is editing the information on one of the tabs I want to display a message box confirming whether the data should be saved.

Hi, You have to display a message box, when closing a form or changing one tab to another.

If Changing from one tab to another,
set editing flag on All the controls change event (Current Tab) and clear it after the confirmation. Suppose Text1 is in First Tab, then

Dim bEditing As Boolean

Private Sub tabMainForm_Click(PreviousTab As Integer)
    If bEditing Then
      Select Case MsgBox("Save changes?", vbYesNoCancel, applicationTitle) = vbYes
      Case vbYes
         cmdSave_Click (tabMainForm.Tab)
      Case vbNo
         
      Case vbCancel
         Exit Sub
      End Select
    End If
    'ClearFlag
    bEditing = False
End Sub

Private Sub Text1_Change()
   bEditing = True
End Sub

Thank you both for your replies, the MouseDown event worked fine, but I now have the same problem with a ListBox.

The names of items are listed in a ListBox, when an item is selected its details are filled into several TextBoxes underneath the list.

Basically I need the same kind of thing; if the user tries to select a different list item while editing = True then I want to display the message and perform no action. The MouseDown event is firing but the ListIndex is still changing.

Any ideas? I know I could set the ListBox.Enabled = False but I would rather use a simpler solution as before.

Hope someone can help,

Andy

This article has been dead for over six months. Start a new discussion instead.