Option Button

M

molsonexpert

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.
 
A

Allen Browne

You will need to have some understanding of VBA to achieve this.

Use the AfterUpdate event procedure of the option group to perform the
calcuation. Use Select Case to determine which calc. This example assigns a
value to the text box named Result, depending on the value in the text box
named Source:

Private Sub Frame0_AfterUpdate()
Select Case Frame0.Value
Case 1
Me.[Result] = Me.[Source]
Case 2
Me.[Result] = Me.[Source] * 55
Case 3
Me.[Result] = Me.[Source] / 4
Case ...
End Select
End Sub

To make it mandatory, consider the flow of your form. Is there some kind of
Ok button where the value is applied? If so, you could use this button to
perform the check for IsNull() or =0 before applying the result.
 

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