View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
[email protected] c1802362@gmail.com is offline
external usenet poster
 
Posts: 15
Default message box error trapping issue

I need some help resolving an issue where my msgbox goes into a terminal loop.

I have a form with a runtime-generated list of names with check boxes next to each, plus €˜Go and €˜Cancel buttons. When the user launches the routine, the list box populates with names it reads from within the file. The user selects the names of the individuals he/she is interested in and the routine launches without issue.

As part of the code, I have error traps for canceling and exiting the routine for various reasons. They all work normally, except for the condition where the user clicks the launch button with no names selected. I have the following error trap code:


sub ChooseNames
dim i as Integer, j as Integer
Dim bFlg as Boolean

' some code ....

resetChoice:

j = 0

bFlg = False

For i = 0 To form1.ListCount - 1
' run through list box of names looking for
If form1.Selected(i) = True Then
'do some action here
j = j + 1 €˜ index to next name in list
bFlg = True
End If
Next i

€˜ error trap
If bFlg = False Then
MsgBox "Select one or more names, then click " & _
"'Go or click 'Cancel'", vbInformation, "Selection Required"
GoTo resetChoice
End If

' more code ....

End Sub


If any name is selected the bFlg is tripped to TRUE and the code executes normally. If no names are selected bFlg remains false and the error trap is activated. If the user responds to the message and selects €˜Cancel, the routine exits normally. If the user hits the €˜Go button without any of the names being selected, the message reappears and even with the form set to modal as true, I cant select anything in the list box or get the message box to disappear. So effectively, the user is stuck in a message box loop.

Any suggestions on how to display the message and allow the user to select from the run time list or cancel and exit?

Art