Option Buttons

  • Thread starter Thread starter molsonexpert
  • Start date Start date
M

molsonexpert

Hi All.

Originally posted in microsoft.public.access without a response. Thought I'd
try here (my apologies for the multi-post):

Using Access 2002. I have an unbound control whose format is currency and a
default value of zero. I also have an option group containing 4 option
buttons, with neither of the four selected by default. Once a value is
entered in the control, I would like a calculation to take place depending
on which option button has been selected (there's a different calculation
for each option). Otherwise, the value should remain zero. To be even more
difficult, once a value has been entered, I want it mandatory that one of
the option buttons be selected. What's the best way to do this? I suspect
some sort of if...else and/or case statement in vba, no?

Thanks in advance.
 
Using an Option Group called OptionGroup1, with 4 option buttons in it
(OptionValue 1 through 4 on the individual option button properties), and two
text boxes - one for the user-entered value (ValUser) and another for the
calculated value (ValCalc), here is the code:

ValUser_AfterUpdate()
I IsNull(OptionGroup1) then Exit Sub
Select Case OptionGroup1
Case is = 1
ValCalc = ValUser * 2
Case is = 2
ValCalc = ValUser * 29
Case is = 3
ValCalc = ValUser * 72
Case is = 4
ValCalc = ValUser * 243
End Select
End Sub

The numbers 2, 29, 27, & 243 are, of course, dummy figures to be replaced by
your calculation.

Form_BeforeUpdate()
If Not IsNull (ValUser) and ValUser <> 0 Then
If IsNull(OptionGroup1) then
MsgBox "Please select an option."
Cancel = True
End If
End If
End Sub

This one ensures that if there is a ValUser, there is also an OptionGroup1
entry.
 
Back
Top