Multiple Option Groups Required

SoxPats83

Registered User.
Local time
Today, 12:58
Joined
May 7, 2010
Messages
196
I remember a thread from a while back where someone posted a code showing how to make a selection in an option group required if there is a selection made in another option groupd on the same form. but i cannot seem to find that thread...

what i have is a form that has two option groups (each with three option buttons returning a value of either 1, 2, or 3 back to the table). if the user makes a selection to one of these two option groups, than they MUST make a selection to the other group. any thoughts?
 
Set the default value for both option groups to 0

Then test if either option group has a value greater than 0

Code:
If Me.OptGrp1 > 0 And Me.OptGrp2 = 0 Then
   Error
ElseIf Me.OptGrp1 = 0 And Me.OptGrp2 > 0 Then
   Error
Else
   Ok
End If

Place this at your point of entry
 
I found the below codes from a previous thread, but i am a bit confused as to where to place it. On Cancel? on Click? on Change?

Code:
If Nz(Frame81, 0) = 0 Or Nz(Frame90, 0) = 0 Then
MsgBox ("Please select choices from the option groups")
Exit Sub
End If

there is no record selectors on my form, but only a close button. what i would like is if these requirements are not meet, then the record will not let you save/close.
 
Are you issuing a cancel event? what does the event procedure look like?
 
Are you issuing a cancel event? what does the event procedure look like?
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Nz(Frame81, 0) = 0 Or Nz(Frame90, 0) = 0 Then
MsgBox ("Please select choices from the option groups")
Exit Sub
DoCmd.CancelEvent
End If
End Sub
 
change

DoCmd.CancelEvent


to

Cancel = true

I think. Don't use this event myself
 
Oh I see you're checking for Null. Try this:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Nz(Frame81, 0) <> 0 And Nz(Frame90, 0) = 0 or (Nz(Frame90, 0) <> 0 And Nz(Frame81, 0) = 0) Then
        cancel = true
        MsgBox "Please select choices from the option groups"
    End If
End Sub
You had things the wrong way round.
 
Last edited:
What version of Access are you using? Did you read post #2 earlier?
 

Users who are viewing this thread

Back
Top Bottom