Last post Mar 14, 2013 12:57 PM by Rion Williams
Mar 14, 2013 11:21 AM|simflex|LINK
Hopefully, this is the right forum for this question.
We are using Access database as front end to connect to sql server db.
We have a form and one of the controls is a radio button.
There are 3 options with this control.
We want to make sure that users can check one of the 3 radio buttons before proceeding.
Everything I have tried so far has not worked.
For instance I tried:
if Me.radioButtonName.Value <> 1 or Me.radioButtonName.Value <> 2 OR Me.radioButtonName.Value <> 3
Msg="must make a selection"
No errors but it doesn't work.
Thanks alot in advance
Mar 14, 2013 11:48 AM|Rion Williams|LINK
Have you considered using a
RadioButtonList Control, which will generate each of your options and you could use it to check if any of them had been checked?
<form id="form1" runat="server">
<!-- Your RadioButtonList with three options -->
<asp:RadioButtonList ID="YourRadioButtonList" runat="server">
<!-- A Label to store any error messages -->
<asp:Label ID="ErrorLabel" runat="server" />
<!-- A Submit Button to Submit Your Form -->
<input type="submit" value='Submit' />
along with the following server-side code :
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'If a PostBack occured'
If (IsPostBack) Then
'Check if a value was selected'
If (YourRadioButtonList.SelectedItem Is Nothing) Then
'If not output an error'
ErrorLabel.Text = "Please select a value!"
'Your Database call goes here'
You'll need to make sure that you are also checking the SelectedItem property instead of the
SelectedValue as well.
Mar 14, 2013 11:52 AM|simflex|LINK
Ron, that's very much for your prompt response.
I know how to validate radiobutonList using .net but in this case, I am using Access Form as front end.
So, your solution won't work for an Access Form.
Sorry if I wasn't clear before.
Mar 14, 2013 11:59 AM|Rion Williams|LINK
Are you using an Option Group for all of these (so that only a single one can be selected at a time)? I'm trying to find the Documentation for Access Forms (as it has really been forever since I have even been around them).
It's likely just a simple property that isn't being checked properly and probably should be something like
Value or OptionValue, I'll keep looking :
'Attempts to check each of them'
If(Me.radioButtonName.Value <> 1 OR Me.radioButtonName.Value <> 2 OR Me.radioButtonName.Value <> 3) Then
'Set your message here'
'Checks if there is a value at all'
If(Not Me.radioButtonName.Value) Then
'Set your message here'
(Pardon any syntax errors as my experience in this area is rather limited)
Mar 14, 2013 12:05 PM|simflex|LINK
Thank you Rion.
Yes, it should be an Option Group where only one single one can be seletected at a time.
I will keep looking too as I haven't done this before.
Thanks a lot
Mar 14, 2013 12:13 PM|Rion Williams|LINK
I updated my previous answer, you may also want to consider trying a case (switch) statement instead (especially if you are going to end up with any additional options or need some specific logic added) :
Select Case Me.radioButtonName.Value
'Your Message Here'
Mar 14, 2013 12:37 PM|simflex|LINK
I know you said you haven't done this for a while but do I need to put the code in the BeforeUpdate procedure because I tried exactly the same code as the first part of your solution:
If Me.RadioButtonname <> 1... and it wasn't doing anything.
I haven't tried the select case yet. Same question applies here.
Do I need to put in beforeUpdate procedure?
Mar 14, 2013 12:46 PM|Rion Williams|LINK
I can't really say with any kind of certainty. You'll likely need someone with a bit more experience using Access Forms that I have, but I'll be glad to try and help you figure it out.
What does your BeforeUpdate procedure currently look like? According to
this discussion it looks like that is typically where the validation is handled within Access Forms so that sounds like the correct place to put it.
Mar 14, 2013 12:47 PM|simflex|LINK
I will be back in a sec.
Thanks a million Rion.
Mar 14, 2013 12:57 PM|Rion Williams|LINK
No problem. I hope it works out.