Seemingly Simple Radio Button VBA Code

B

Brenda

But I am at a impass!

First of all, thanks in advance for any help you may be able to provide.

My MSAccess VBA situation is this - I am a novice trying to learn MSAccess
and have made many strides. I have successfully developed a membership
database for which I can swipe a drivers license for membership information
for a club. I am now "tweaking" it and would like to add a couple of radio
buttons that once selected would place text in my Members table to the
current record for which data is being entered through a form. If the radio
buttons are left not selected, the field would remain blank. Also, when one
of the radio buttons are selected, a field for membership dues for which is
currently defaulted to $1.00 would go to $0.00. The radio buttons are
grouped.

I am at a mental road block for the code. Any help would be appreciated.
Here are the specfics.
table name = Members
field name for data from selected radio buttons = Dues_Exempt
field name for default $1.00 membership dues = Member_Dues
radio button #1 name = rb1 (text entry to Dues_Exempt field would be "No Charge - Senior Citizen"
radio button #2 name = rb2 (text entry to Dues_Exempt field would be "No Charge - Other"
radio button group name = radio_buttons (source data is Dues_Exempt)
form name = Members

Thanks!
 
L

Larry Linson

Without changing your approach or naming, and assuming you have left the two
buttons rb1 and rb1 in the Option Group radio_buttons with their default
values of 1 and 2, but given the group a default value of 0, in the Before
Update of your form, the following code should do what you want:

If Me.radio_buttons = 1 Then
Me!DuesExempt = "Exempt - Senior Citizen"
Me!MemberDues = 0
ElseIf Me.radio_buttons = 2 Then
Me!DuesExempt = "Exempt - Other"
Me!MemberDues = 0
End If

Note: as shown here, this code is untested.

Now I will offer some suggestions:

Many Access developers (including me) prefer to use the Reddick VBA Naming
Convention, which you will find at http://www.xoc.net/standards/rvbanc.asp.
To automate naming of Controls on forms with the simplest level of the
Reddick Convention, you can obtain from MVP Arvin Meyer's website, a free
download called "FixNames".

Using your names for the Fields in the Tables, but running FixNames on the
form, the Controls are renamed, and the code (this is tested) in the
BeforeUpdate of the Form is:

If Me.optradio_buttons = 1 Then
Me.txtDuesExempt = "Exempt - Senior Citizen"
Me.txtMemberDues = 0
ElseIf Me.optradio_buttons = 2 Then
Me.txtDuesExempt = "Exempt - Other"
Me.txtMemberDues = 0
End If

However, if you accidentally click either of the radio buttons, it would be
a good idea to have some way to reset to "Regular Dues"... that could be an
additional radio button for Regular, with code that would clear the
DuesExempt Control and reset MemberDues to $1.00.

An even better way would be to "normalize" with a separate table of
MemberClass, containing

MemberClassID Numeric Unique ID
MemberClassDues Currency Dues for this class of member
MemberClassName Text Name of class, e.g. "Regular", "Exempt -
Senior Citizen"

Use a Combo Box to select a class, and save the MemberClassID... then
whenever you need to display the class type, and/or dues, use a query
joining the Members table (in my scheme of things, that would be
"tblMembers") with the MemberClass table ("tblMemberClasses"). At any time,
then, you could change the Member's Class.

Good luck with your application. (Since you have it almost working now, you
might even want to wait until your next application to consider naming
schemes and normalization. <SMILE>)

Larry Linson
Microsoft Office Access MVP
 
B

Brenda

Thank you Larry. This looks so simple now. I will give this code a try and
see what happens!

Sincerely.

Brenda
 

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