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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using options

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am making a database for work.
It is almost finisht. the biggest problem so far is that I want to use option buttons.
I have 4 options(option1, option2, option3, option4 and a command button) and when I click option1 then form1 mustopend and so on.

Does anybody know how to program this?

F1-nr1 [pc3]
 
Ok...here goes

Assumption: you create the option group with the option group wizard and left the values default.

An option group is merely a collection of subcontrol for the overall option frame. Each of the options is assigned a value, by default 1, then 2, then 3, and so on. This option value is passed to the frame, which then has the value of the option selected. You merely tell the command button to llok for the value of the frame and perform the action, like below:

Frame1
Option1 = Value 1
Option2 = Value 2
Option3 = Value 3
Option4 = Value 4

cmdButton, OnClick Event
If Me![Frame1].Value = 1 Then
Do Some Code
ElseIf Me![Frame1].Value = 2 Then
Do Some Code
ElseIf Me![Frame1].Value = 3 Then
Do Some Code
ElseIf Me![Frame1].Value = 4 Then
Do Some Code
End If

OR

Select Case Me![Frame1].Value
Case 1
Do Some Code
Case 2
Do Some Code
Case 3
Do Some Code
Case 4
Do Some Code
End Select

Either of these code strings will give you waht you want. I prefer to use a Case Select if there are more than two or three options...

If you did not leave the values for the options default, just go to the properties of each option button and see what you set the value. Then change the 1,2,3,and4s above to whatever your values are.

As for opening a form, if you need some help with that....
DoCmd.OpenForm "formname" is the most basic call for this and will work. There are other options if necessary, check the help file or let me know you need more assistance.

Hope this helps.





There is no I in team. [elf]

Robert L. Johnson III, A+, Network+, MCP
robert.l.johnson.iii@citi.com
 
it has been a great help to me

tnx 4 it

1 more question: every time I start the database all the option al grey. How do I mak them all blank?

F1-nr1
 
The reason it is greyed out is the fact that you probably don't have a default button selected. You can go to frame properties and set a Default Value to one of the button's values. My only problem with this is having something preselected for my user. Usually not a solution for my work. Well, I used to not worry about it myself, but I just tried this out and it worked great.......

Open your form in design mode, click on the option button in your toolbox, and add an option button to the option group. Right click this new option and display properties. Set the value of the option to some stupid number....I set mine to 99999. The set the visible property to No. This will hide the button and not make it visible.

Next, set the default value of your Frame to the same stupid value.....99999. This will, by default, have that option button checked when the form is started.

By doing this, the form will automatically pick the "stupid" value and set it. This will cause all the other options to be "white" since they are unselected. When the user picks a button, voila, all is well.

You may consider adding some error catching to make sure the user selected a valid button before hitting the command button. For Example:

In the command button OnClick Event:

If Me![Frame1].Value = 99999 Then
MsgBox("You did not select a valid option.")
Exit Sub
End If

This will force the user to pick an option before the command button can run its processes.

Good Luck!
There is no I in team. [elf]

Robert L. Johnson III, A+, Network+, MCP
robert.l.johnson.iii@citi.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top