Using tabpage control to handle wizard-like
There is always a need to do some sequential steps as a whole process which need to apply with some validations
today we will discuss how to build a wizard-like form in ms access
Open a new modal form and define high and width of it as per your needs
Save the form as frmWizard
Insert a tabpage control inside the detail section
Rename the tabpage as TabCtlWiz
Create 4 buttons and draw it like image aside
Name them btnCancel, btnPrevious, btnNext and btnFinish
Adjust the caption property to show buttons like image
Use code bellow to adapt functionality
Form Property
Tab Page Property
Next, Previous, Finish and Cancel buttons
Option Compare Database
Option Explicit
Private Sub btnCancel_Click()
' close without save
DoCmd.Close acForm, Me.Form.Name, acSaveNo
End Sub
Private Sub btnFinish_Click()
' do some code and check some validation then close the form
DoCmd.Close acForm, Me.Form.Name, acSaveNo
End Sub
Private Sub btnNext_Click()
With Me.TabCtlWiz
If .Value < .Pages.Count - 1 Then
.Value = .Value + 1
' Enable Previous button when not on the first page
Me.btnPrevious.Enabled = True
End If
' Disable Next button when on the last page
Me.btnNext.Enabled = (.Value < .Pages.Count - 1)
' Enable Finish button only on the last page
Me.btnFinish.Enabled = (.Value = .Pages.Count - 1)
Me.Caption = "Wizard Title - Page " & .Value + 1 & " of " & .Pages.Count
End With
End Sub
Private Sub btnPrevious_Click()
With Me.TabCtlWiz
If .Value > 0 Then
.Value = .Value - 1
' Enable Next button when not on the last page
Me.btnNext.Enabled = True
End If
' Disable Previous button when on the first page
Me.btnPrevious.Enabled = (.Value > 0)
' Disable Finish button when not on the last page
Me.btnFinish.Enabled = (.Value = .Pages.Count - 1)
Me.Caption = "Wizard Title - Page " & .Value + 1 & " of " & .Pages.Count
End With
End Sub
Private Sub Form_Load()
' Initialize buttons' state
With Me.TabCtlWiz
Me.btnNext.Enabled = (.Value < .Pages.Count - 1)
Me.btnPrevious.Enabled = (.Value > 0)
Me.btnFinish.Enabled = (.Value = .Pages.Count - 1)
Me.Caption = "Wizard Title - Page " & .Value + 1 & " of " & .Pages.Count
End With
End Sub