Info

Another use of a unique list of values is to quickly populate a list box or a combo box on a userform. Say that you have a macro that can run a report for any one specific customer. To allow your clients to choose which customers to report, create a simple userform. Add a list box to the userform and set the list box's MultiSelect property to 1-fmMultiSelectMulti. I named my form frmReport. In addition to the list box, I have four command buttons: OK, Cancel, Mark All, Clear All. The code to run the form follows. Note the Userform_Initialize procedure includes an Advanced Filter to get the unique list of customers from the dataset:

Private Sub CancelButton_Click()

Unload Me End Sub

Private Sub cbSubAll_Click()

For i = 0 To lbCust.ListCount - 1 Me.lbCust.Selected(i) = True Next i End Sub

Private Sub cbSubClear_Click()

For i = 0 To lbCust.ListCount - 1 Me.lbCust.Selected(i) = False Next i End Sub

Private Sub OKButton_Click()

If Me.lbCust.Selected(i) = True Then

1 Call a routine to produce this report RunCustReport WhichCust:=Me.lbCust.List(i)

0 0

Post a comment