Full Version: Force User to make a selection
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
kybb1
Good Morning All,

I have an issue that I just don't know how to resolve. So...I came to the place that has the best Access Guru's.

On my form, frmBHL, I have 2 fields, txtInpatient, txtCMgmt, and txtHH. One (1) of these three MUST be choosen. With that said, I thought about putting some code in the OnClose event of the form. I know how to validate one (1) field....I just don't know the code to verify if 1 of the 3 has a value.

If there isn't a value, the user CAN'T exit the form...they must go back and input data in 1 of the 3.

Can someone please help me?

Thanks in advance.
freakazeud
Hi,
use the before update event of the form with some code like this:

If Len(Me.txtInpatient & vbNullString) = 0 AND Len(Me.txtCMgmt & vbNullString) = 0 AND Len(Me.txtHH & vbNullString) = 0 Then
MsgBox("One of the 3 controls must be filled out.")
Cancel = True
End If

You could also do this on a custom close button's on click event:

If Len(Me.txtInpatient & vbNullString) = 0 AND Len(Me.txtCMgmt & vbNullString) = 0 AND Len(Me.txtHH & vbNullString) = 0 Then
MsgBox("One of the 3 controls must be filled out.")
Else
DoCmd.Close
End If

You could also loop through the three controls using their tag property and check if they are filled out that way. Many different options here.
BTW...forms hold controls...fields are in tables!
HTH
Good luck
kybb1
Thanks so much....you made it look PERFECTLY easy...I spent more time making my post than you did providing the code.....FANTASTIC!!!!

Have a great day.
freakazeud
You're welcome frown.gif
Glad I could assist.
Good luck on future projects!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.