Show/Hide Option Buttons Access 2007

R

RedBeard

I just got Access 2007 the other day and I'm poking about with various
functions, but, I want to do something and I can't figure out how to
do it.

I have three Option Buttons with a label next to them.

What I want to do is the following:

If I select Option 1, the other two options should grey out (Enabled =
False I think?) and the label go "dim" as well.

and if I select option 2, 1 and 3 should grey out along with the
labels.

and so on...

Now, I can't for the life of me figure out how to do this, so any help
would be gratefully received.

Thanks in advance.
 
J

John Spencer

And if you do that and change your mind then what do you propose to do?
You've locked at the ability to change the data in the form at this point.

To do this, you would need a sub like the following.
Private Sub sSetFrameEnabled()
Select NZ(Case Me.Frame19,0)
Case 0
Me.Option22.Enabled = True
Me.Option24.Enabled = True
Me.Option26.Enabled = True
Case 1
Me.Option22.Enabled = True
Me.Option24.Enabled = False
Me.Option26.Enabled = False
Case 2
Me.Option22.Enabled = False
Me.Option24.Enabled = True
Me.Option26.Enabled = False
Case 3
Me.Option22.Enabled = False
Me.Option24.Enabled = False
Me.Option26.Enabled = True
End Select

End Sub

You call that sub in the Frame's (option group control) on update event and if
you want that same functionality when you move from record to record you will
need to call the code in the FORM's Current event.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
R

Ron2006

The question that I then ask, is: What is the user supposed to do if
he/she picks the wrong one by accident? You have just disabled the
remaining selections so they can't change their mind.

What I usually do as an alternative is to make the lbl for the
selected option bold property true and the bold property for the
others false. That way they can change their mind. (OR make the proper
selection that they really wanted.)

The logic is exactly the same as the suggested code except that it is
the bold property (for the associated lbl) that is set to true or
false.

Ron
 
R

RedBeard

Well, I was thinking about doing a little quizgame thing to practice
how access works.
No time for second guesses :)

I appreciate the code below, but I don't quite get what Me.Frame19,0
does, would you mind elaborating?

Thanks
 
J

John Spencer

Nz(Me.Frame19,0) forces a value of zero if no option has been selected.

If you are on a new record and the Option group is bound to a field (and you
haven't set a default value for the option group) the option group value will
be null. The Nz replaces Null with zero so the case statement will work.

If you do have a default value of zero, then there is no problem.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
R

RedBeard

Nz(Me.Frame19,0) forces a value of zero if no option has been selected.

If you are on a new record and the Option group is bound to a field (and you
haven't set a default value for the option group) the option group value will
be null.  The Nz replaces Null with zero so the case statement will work.

If you do have a default value of zero, then there is no problem.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Well, this was more complicated than I imagined :)

I don't suppose you know of any beginner tutorials I could have a look
at to understand better?

Thanks for all the help!
 
J

John Spencer

You can check out the following for basics on Access.

Jeff Conrad's resources page:
http://www.accessmvp.com/JConrad/accessjunkie/resources.html

The Access Web resources page:
http://www.mvps.org/access/resources/index.html

A free tutorial written by Crystal (MS Access MVP):
http://allenbrowne.com/casu-22.html
http://www.everythingaccess.com/tutorials.asp?ID=Access-basics:-free-tutorial

MVP Allen Browne's tutorials:
http://allenbrowne.com/links.html#Tutorials

Here's a primer with 23 well defined, well written, clearly named chapters:
http://www.functionx.com/vbaccess/index.htm

--

I have a Word document I call Access Links.doc, that I think you will find
quite helpful. You can download a zipped copy from here:

http://www.accessmvp.com/TWickerath/

For the present time, concentrate on just the first couple of pages. This
includes information on special characters to avoid, reserved words, database
design, best practices (make sure that you have the latest updates), Name
Autocorrect, Relationships, along with a lot of useful links to other web
sites. Also, head on over to Access MVP Crystal's new site and download her
Access Basics tutorials:

http://www.accessmvp.com/Strive4Peace/Index.htm


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
J

John Spencer

You can check out the following for basics on Access.

Jeff Conrad's resources page:
http://www.accessmvp.com/JConrad/accessjunkie/resources.html

The Access Web resources page:
http://www.mvps.org/access/resources/index.html

A free tutorial written by Crystal (MS Access MVP):
http://allenbrowne.com/casu-22.html
http://www.everythingaccess.com/tutorials.asp?ID=Access-basics:-free-tutorial

MVP Allen Browne's tutorials:
http://allenbrowne.com/links.html#Tutorials

Here's a primer with 23 well defined, well written, clearly named chapters:
http://www.functionx.com/vbaccess/index.htm

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
R

RedBeard

You can check out the following for basics on Access.

Jeff Conrad's resources page:http://www.accessmvp.com/JConrad/accessjunkie/resources.html

The Access Web resources page:http://www.mvps.org/access/resources/index.html

A free tutorial written by Crystal (MS Access MVP):http://allenbrowne.com/casu-22.html...ccess.com/tutorials.asp?ID=Access-basics:-fre...

MVP Allen Browne's tutorials:http://allenbrowne.com/links.html#Tutorials

Here's a primer with 23 well defined, well written, clearly named chapters:http://www.functionx.com/vbaccess/index.htm

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Even though some very nice people provided me with help and gave
examples, I still don't understand Option Groups at all.

I went back a step and tried simplifying everything but I just don't
get it.

What I currently have is this:

A form with an Option group that has three options and one text box.

What I want to accomplish is this: selecting the topmost option
displays 1 in the text box,
second option displays a 2 and option 3 should show a 3.

Help please, I feel so dumb :(
 
J

John Spencer

If you used the wizard to set up the option group, then each option in the
group sets the value of the option group to a value from 1 to n (n being the
number of options you have in the option group).

The option group (probably named frame something) is where the value is
changed (stored). So if you have a text box next to the option group, you
should be able to set its source to
=[NameOfOptionGroupControl]

Or you can use the option group's after update event to set the value of the
text box control
Me.NameOfTextBox = Me.NameOfOptionGroupControl

You can bind (set the control's source) either (or both) controls to a field.
If you bind both controls to the same field then changing the value in one
should automatically change the value in the other since they are both showing
the value of the field.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 

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