473,385 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

option button help

What I am trying to do is have a set of option buttons which are
required to click one. If the person doesn't click any before insert,
they get an error. If they do click one, it inserts into the field in
the table and then clears the form for the next entry.

I have a form tied to a table. In the table is a lookup field.
In the form I have a frame with 5 option buttons in it.
Outside the frame I have a text box.
I bound the text box to the lookup field.
The form also has an Insert button.

The code I am using is:
cmdInsert_Click()
If Me.opt1.optionvalue = True Then
Me.txtOption.Text = "RF"
End If
If Me.opt2.optionvalue = True Then
Me.txtOption.Text = "25"
End If
..
..
..
..
DoCmd.GoToRecord , , acLast

On Error GoTo Err_cmdUpdate_Click

If Me.Dirty Then
Me.Dirty = False
End If
If Not Me.NewRecord Then
RunCommand acCmdRecordsGoToNew
End If
Me.opt2000.OptionValue = False
Me.opt2500.OptionValue = False
Me.opt700.OptionValue = False
Me.optHD.OptionValue = False

The way I understand it, if the option button is set to True then my
textbox should receive the value from the If statement. If not true,
then the box stays empty. Also, after I Insert the data, the option
buttons will be Off. I have tried this code with opt1.Value set to
True and False as well. I either get a Null value error from the table
because the lookup field is required, or I get a 'This expression has
No Value' error.
What am I doing wrong? Also can you include a snippet to get
me headed in the right direction.
Feb 12 '06 #1
1 4414

"Stephen D Cook" <st******@comcast.net> wrote in message
news:ee********************************@4ax.com...
What I am trying to do is have a set of option buttons which are
required to click one. If the person doesn't click any before insert,
they get an error. If they do click one, it inserts into the field in
the table and then clears the form for the next entry.

I have a form tied to a table. In the table is a lookup field.
In the form I have a frame with 5 option buttons in it.
Outside the frame I have a text box.
I bound the text box to the lookup field.
The form also has an Insert button.

The code I am using is:
cmdInsert_Click()
If Me.opt1.optionvalue = True Then
Me.txtOption.Text = "RF"
End If
If Me.opt2.optionvalue = True Then
Me.txtOption.Text = "25"
End If
.
.
.
.
DoCmd.GoToRecord , , acLast

On Error GoTo Err_cmdUpdate_Click

If Me.Dirty Then
Me.Dirty = False
End If
If Not Me.NewRecord Then
RunCommand acCmdRecordsGoToNew
End If
Me.opt2000.OptionValue = False
Me.opt2500.OptionValue = False
Me.opt700.OptionValue = False
Me.optHD.OptionValue = False

The way I understand it, if the option button is set to True then my
textbox should receive the value from the If statement. If not true,
then the box stays empty. Also, after I Insert the data, the option
buttons will be Off. I have tried this code with opt1.Value set to
True and False as well. I either get a Null value error from the table
because the lookup field is required, or I get a 'This expression has
No Value' error.
What am I doing wrong? Also can you include a snippet to get
me headed in the right direction.

I don't know how you have set up the option group, but typically the option
values will not be True/False. Rather, you would give them distinct values
like:
opt1.OptionValue=1
opt2.OptionValue=2
opt3.OptionValue=3
Now when you press the button, you look at the value of the Option Group
control as a whole:

Select Case Me.grpOptions.Value

Case 1: MsgBox "One is selected"

Case 2: MsgBox "Two is selected"

Case 3: MsgBox "Three is selected"

Case 4: MsgBox "Four is selected"

Case 5: MsgBox "Five is selected"

Case Else: MsgBox "None are selected"

End Select
I'm not going to comment on the rest of the code except to say, it looks
like you are hard-coding values that possibly should be stored in a table,
e.g. Opt1=>"RF" Opt2=>"25"
If you are sure they should not be looked up from a table, then perhaps use
constants so your code makes more sense:
Private Const OPT_FIRST_ONE As Long=1


Feb 12 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Adrian | last post by:
Access 2000 How can I get the properties of the selected option button within an option group? With the code below it returns the 'HelpcontextID) of the option group, and not the ID...
3
by: Andy K | last post by:
Hello everyone, I have a form with an option button on it. I am having problems to set the value of this to is previous state/selection. For instance if someone navigates from the main menu to...
1
by: Steven | last post by:
I have created a form in MS Access 2000. The form retrieves... For simplicity, let's say User Names... The form and text box is pretty much setup for display only (the text box can not be edited)....
6
by: ducky | last post by:
I have set up two option buttons. When option button 1 is selected I need to make sure that the combo box located beside Option button 2 is cleared. In turn I need to make sure that if a value is...
4
by: hexagram | last post by:
Hi guys Goodmorning i need a big help, can anyone give me a script for option button, i have create a application form which i must create a option button this is the scenario Types of leave ...
1
by: sparksol | last post by:
I have a form with a drop down box. If you select an option in the drop down box (depending which option is selected) one or two textbox(es) and a submit button display. I would like to keep the...
2
by: sara | last post by:
Hi I'm having a very strange problem and need HELP!! I have a form for the user to choose a report (radio button in an option group) and parameters (Dates, Season). Click the option button,...
2
beacon
by: beacon | last post by:
Hi everybody, I have a form that has a combo box that asks the user to select the program they work on. Once the user selects the program, a SQL statement populates the row source for 4 staff...
1
by: grego9 | last post by:
I have two option buttons - Diplayed as Option Button 76 and Option Button 77 in the name box on a tab called "AMEND" . When Option button 76 is slected I want a drop down box called Drop Down 43...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.