Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stop Tab Control Change Event

Status
Not open for further replies.

MelissaKT

Technical User
Jun 22, 2004
95
US
I would really appreciate any help with this....
I have an unbound form with a tab control on it. Each page has several unbound text boxes. I have a save button on the form (in the header). I don't want the user to be able to change pages unless they have saved their work. How do I cancel the tab's change event and keep it on the correct page?
 
To cancel updates to any control, I think the best method would be:

Code:
Private Sub SomeTextBox_BeforeUpdate(Cancel As Boolean)
  If [green]PreviouslySavedData[/green] Then
  Else
    Cancel = True
End Sub

Where the PreviouslySavedData would be a public variable, perhaps, set to True/False (boolean) as to whether or not the user previously saved the other changes.
 
Code:
Private Sub TabCtl0_Change()
  If Not blnsaved Then
    TabCtl0.Pages(0).SetFocus
  End If
End Sub
keeps focus on the first page
where blnSaved is a boolean variable
 
Hey Maj, good to hear from you again! I had found this on a different website - kinda what I wanted - just have to change it to apply to my unbound form
Code:
Private Sub tabCtl_Change() 
    Static blnChanging As Boolean 
    Static lngOldTab As Long 
    Static lngNewTab As Long 

    If Not blnChanging Then 
        If Me.Dirty Then 
            blnChanging = True 
            lngNewTab = Me.tabCtl.Value 
            Me.tabCtl.Value = lngOldTab 
            Select Case MsgBox("Do you want to save your changes?", _ 
                vbYesNoCancel Or vbQuestion, _ 
                "Save changes?") 
                Case vbYes 
                    Me.Dirty = False 
                    Me.tabCtl.Value = lngNewTab 
                Case vbNo 
                    Me.Undo 
            End Select 
            blnChanging = False 
        End If 
        lngOldTab = Me.tabCtl.Value 
    End If 
End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top