Force a user to enter a value

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!
 
G

Guest

Enter the code in the before update property of the form
and add
cancel=true , incase no item is selected in Listbox
that will stop the user from exit the form until the data is in.

or
you can put the code in the UnLoad propery of the form
also with cancel=true
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top