G
Guest
I have a form with several controls in which I would like to force the user
to have to select a value from a list box if a certain checkbox is checked.
For example lets say we have:
Checkbox1
Listbox1
What I would like to happen is the following:
If the value of the Checkbox is true, then check to see if the user selected
an item in Listbox1. If an item is not selected in Listbox1, then display a
message and return the user to Listbox1.
I can get all of this to work, but the check is done only once. I would
like to create a loop to ensure that if the user is returned to Listbox1,
they cannot leave the control until they have selected a value.
My code:
Dim Flag As String
Dim ctlList As Control
Dim n As Integer
Set ctlList = Forms!OUTREACH_RECRUITMENT_F!lstProviderType
Flag = False
While Flag = False
If Recruitment.Value = True Then
For n = 0 To ctlList.ListCount - 1
If ctlList.Selected(n) = True Then
Flag = True
Else
MsgBox "Please select a provider type." _
, vbExclamation + vbOKOnly, "PROVIDER TYPE"
lstProviderType.SetFocus
End If
Next n
End If
Loop
Set ctlList = Nothing
Thanks in advance!
to have to select a value from a list box if a certain checkbox is checked.
For example lets say we have:
Checkbox1
Listbox1
What I would like to happen is the following:
If the value of the Checkbox is true, then check to see if the user selected
an item in Listbox1. If an item is not selected in Listbox1, then display a
message and return the user to Listbox1.
I can get all of this to work, but the check is done only once. I would
like to create a loop to ensure that if the user is returned to Listbox1,
they cannot leave the control until they have selected a value.
My code:
Dim Flag As String
Dim ctlList As Control
Dim n As Integer
Set ctlList = Forms!OUTREACH_RECRUITMENT_F!lstProviderType
Flag = False
While Flag = False
If Recruitment.Value = True Then
For n = 0 To ctlList.ListCount - 1
If ctlList.Selected(n) = True Then
Flag = True
Else
MsgBox "Please select a provider type." _
, vbExclamation + vbOKOnly, "PROVIDER TYPE"
lstProviderType.SetFocus
End If
Next n
End If
Loop
Set ctlList = Nothing
Thanks in advance!