Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Radio Button Question 2

Status
Not open for further replies.

jbento

Technical User
Jul 20, 2001
573
US
I have 3 radio buttons on a form, not a option group. I want the user to have to choose one before closing the form. They are called: RadioButton1, RadioButton2, & RadioButton3. The following code I'm using doesn't work correctly, because I have to choose each radio button before the form closes. I want the user to only have to choose one, before the form closes. Here is the code I'm using. This is on the UnLoad Event, because the OnClose Event doesn't work with this.

Private Sub Form_UnLoad()
Dim No_Buttons_Selected As Boolean
No_Buttons_Selected = False
If Me!RadioButton1.Value = False Then
No_Buttons_Selected = True
End If
If Me!RadioButton2.Value = False Then
No_Buttons_Selected = True
End If
If Me!RadioButton3.Value = False Then
No_Buttons_Selected = True
End If
If No_Buttons_Selected Then
MsgBox "Please select a Radio Button"
Cancel = True
End If

End Sub

Can anyone help me with this problem, I would surely appreciate any help anyone can give me. Thank you all in advance, and have a WONDERFUL day!!!!

Jerome Benton
JERPAT Web Designs
GOD Is Good All The Time!!!
 
Jerome,

Try your code in the BeforeUpdate event of the form. The Unload event happens after the form is already closed, and it doesn't offer the Cancel boolean.....
 
You set the No_Buttons_Selected to false at the beginning of your function. What happens if they check the first button only? Then when the code checks radio button 2 & 3 (which are NOT checked), it will set No_Buttons_Selected to True.

Instead only use 1 if statement, but use AND to check if all three are not checked.

Private Sub Form_UnLoad()
Dim No_Buttons_Selected As Boolean
No_Buttons_Selected = False
If Me!RadioButton1.Value = False AND Me!RadioButton2.Value = False AND Me!RadioButton3.Value = False Then
No_Buttons_Selected = True
If No_Buttons_Selected Then
MsgBox "Please select a Radio Button"
Cancel = True
End If

End Sub
 
Right, so our combined effort would be:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
   Dim No_Buttons_Selected As Boolean
   No_Buttons_Selected = False
   If Me!RadioButton1.Value = False AND Me!RadioButton2.Value = False AND Me!RadioButton3.Value = False Then
      No_Buttons_Selected = True
   End If
   If No_Buttons_Selected Then
      MsgBox "Please select a Radio Button"
      Cancel = True
   End If

End Sub
 
I want to first say...thanks to both of you for helping. I used briandh's approach and it WORKED!!!!!!

I really appreciate all the help both of you gave me.

Take care,

Jerome Benton
JERPAT Web Designs
GOD Is Good All The Time!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top