Programming dependencies in a wizard

In most wizards, a user's response on a particular step can affect what's displayed in a subsequent step. In this example, the user indicates which products he or she uses in Step 3 and then rates those products in Step 4. The OptionButtons for a product's rating are visible only if the user has indicated a particular product.

Programmatically, this is accomplished by monitoring the MultiPage's Change event. Whenever the value of the MultiPage is changed (by clicking the Back or Next button), the MultiPage1_Change procedure is executed. If the MultiPage control is on the last tab (Step 4), the procedure examines the values of the CheckBox controls in Step 3 and makes the appropriate adjustments in Step 4.

In this example, the code uses two arrays of controls - one for the product CheckBox controls (Step 3)

and one for the Frame controls (Step 4). The code uses a For-Next loop to hide the Frames for the products that are not used and then adjusts their vertical positioning. If none of the check boxes in Step 3 is checked, everything in Step 4 is hidden except a TextBox that displays Click Finish to exit (if a name is entered in Step 1) or a name is required in Step 1 (if a name is not entered in Step 1). The MultiPagel_change procedure follows:

Private Sub MultiPage1_Change() ' Set up the Ratings page?

If MultiPagel.Value = 3 Then ' Create an array of CheckBox controls

Dim ProdCB(1 To 3) As MSForms.CheckBox Set ProdCB(1) = cbExcel Set ProdCB(2) = cbWord Set ProdCB(3) = cbAccess

Create an array of Dim ProdFrame(1 To Set ProdFrame(l) = Set ProdFrame(2) = Set ProdFrame(3) =

Frame controls

3) As MSForms.Frame

FrameExcel

FrameWord

FrameAccess

TopPos = 22 FSpace = 8 AtLeastOne = False

Loop through all products For i = 1 To 3

If ProdCB(i) Then

ProdFrame(i).Visible = True ProdFrame(i).Top = TopPos

TopPos = TopPos + ProdFrame(i).Height + FSpace AtLeastOne = True

Else

ProdFrame(i).Visible = False End If Next i

' Uses no products?

If AtLeastOne Then lblHeadings.Visible = True Image4.Visible = True lblFinishMsg.Visible = False

Else lblHeadings.Visible = False Image4.Visible = False lblFinishMsg.Visible = True If tbName = "" Then lblFinishMsg.Caption = _

"A name is required in Step 1."

Else lblFinishMsg.Caption = _ "Click Finish to exit."

End If End If End If End Sub

0 0

Post a comment