Guiding User Selection of Option Groups (1 Viewer)

Endojoe

Registered User.
Local time
Today, 08:34
Joined
Apr 7, 2009
Messages
20
I have a form with 4 Option Groups, and I need to guide the user through the selection process in a step by step manner. I have tried using some VB code to set the Option Groups to invisible, then make them visable again after a selection is made in each group, in the order they need to be selected in, but this only works when I create a new record, most likely because I'm using the 'On Current' event to fire the code...but when I try to put it anywhere else it won't work at all...the code...
Code:
Private Sub Form_Current()

If Me.opt_Export_Domestic = 0 Then
    Me.opt_Cert_Type.Visible = False
    Me.opt_Assy_SubAssy.Visible = False
    Me.opt_PMA_ASSY.Visible = False
ElseIf Me.opt_Export_Domestic = 1 Then
    Me.opt_Cert_Type.Visible = True
    Me.opt_Assy_SubAssy.Visible = True
    Me.opt_PMA_ASSY.Visible = True
ElseIf Me.opt_Export_Domestic = 2 Then
    Me.opt_Cert_Type.Visible = True
    Me.opt_Assy_SubAssy.Visible = True
    Me.opt_PMA_ASSY.Visible = True
ElseIf Me.opt_Export_Domestic = 3 Then
    Me.opt_Cert_Type.Visible = True
    Me.opt_Assy_SubAssy.Visible = True
    Me.opt_PMA_ASSY.Visible = True
    
End If

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.DESCRIPTION, _
vbCritical, "Error in procedure Form_Current..."
Resume ExitProc

End Sub

Now...these Option Groups have been added to an existing form thats attached to a table with well over 6000 records that were not created using the option groups, my goal is to be able to use this code to walk the user through the Option Group selection process on existing records when it becomes necessary. But I can't seem to figure out what Event to use, I've tried all of them that seem logical to me. :(

When the form loads, all Option Groups are visible until I go to create a new record, then they disappear as the code instructs them to, and they stay gone as I move back through records that have not had any selections made, but as soon as I pass through a record that has had selections made, all option groups re-appear and they stay visible even when I go to records that have no selections made again...I'm baffled... Any thoughts or suggestions on how to make this work how I want it to? Or any better ideas on how to achieve what I'm aiming for would be welcomed! :) Thanks.
 

missinglinq

AWF VIP
Local time
Today, 09:34
Joined
Jun 20, 2003
Messages
6,423
I'm a little fuzzy as to exactly what you're doing here, but I suspect your problem lies in the line

If Me.opt_Export_Domestic = 0 Then

If no selection has been made from the opt_Export_Domestic Option Group, it is not 0 (zero) but rather Null. Try switching this line to

If IsNull(Me.opt_Export_Domestic) Then

The OnCurrent event is the proper event for this kind of thing, but if you want the other Option Groups to become visible immediately after something is selected in the opt_Export_Domestic group, it needs to go in the sub opt_Export_Domestic_AfterUpdate event, as well.

And assuming that you want the other options groups visible if any option in opt_Export_Domestic is selected, then your code can be simplified to:
Code:
If IsNull(Me.opt_Export_Domestic) Then
    Me.opt_Cert_Type.Visible = False
    Me.opt_Assy_SubAssy.Visible = False
    Me.opt_PMA_ASSY.Visible = False
Else
    Me.opt_Cert_Type.Visible = True
    Me.opt_Assy_SubAssy.Visible = True
    Me.opt_PMA_ASSY.Visible = True
End If
 

Endojoe

Registered User.
Local time
Today, 08:34
Joined
Apr 7, 2009
Messages
20
Missinglinq that nailed it! Thank you so much...I'm pretty new to VB stuff, so sometimes I forget that 0 is really Null (and nothing can = Null :D) It's amazing to me that that oversight on my part made the option groups behave the way they did though. :rolleyes: And right on with the simplifying code, I was thinking too hard on figuring out how to make the option groups behave the way I wanted to that I went a little overboard on the code, I actually thought of the AfterUpdate part after I posted the question, but it was a moot point until I figured out the part you helped me with ;) I actually plan on a cascade sort of effect that when a selection is made in one option group, it will display the next one I want them to select from. The IsNull will make that happen for me. Thanks Again!
 

Endojoe

Registered User.
Local time
Today, 08:34
Joined
Apr 7, 2009
Messages
20
Ok, so the default value on the option group I want the user to select from initially is actually set to 0 (so that I can use that value to trigger a reminder box to pop up if no selection is made on newly created records), although on records created before the option group was added to the form the field it is bound to would obviously be Null. So all the working code ended up looking like this (for the future reference of anyone that comes across this thread)...

Code:
Private Sub Form_Current()
If IsNull(Me.opt_Assy_SubAssy) Then
    Me.opt_Cert_Type.Visible = False
    Me.opt_Export_Domestic.Visible = False
    Me.opt_PMA_ASSY.Visible = False
ElseIf Me.opt_Assy_SubAssy = 0 Then
    Me.opt_Cert_Type.Visible = False
    Me.opt_Export_Domestic.Visible = False
    Me.opt_PMA_ASSY.Visible = False
ElseIf Me.opt_Assy_SubAssy = 1 Then
    Me.opt_Cert_Type.Visible = True
    Me.opt_Export_Domestic.Visible = True
    Me.opt_PMA_ASSY.Visible = True
ElseIf Me.opt_Assy_SubAssy = 2 Then
    Me.opt_Cert_Type.Visible = True
    Me.opt_Export_Domestic.Visible = True
    Me.opt_PMA_ASSY.Visible = True
End If
End Sub

Private Sub opt_Assy_SubAssy_AfterUpdate()
If Me.opt_Assy_SubAssy = 1 Then
    Me.opt_Cert_Type.Visible = True
ElseIf Me.opt_Assy_SubAssy = 2 Then
    Me.opt_Cert_Type.Visible = True
End If
End Sub

Private Sub opt_Cert_Type_AfterUpdate()
If Me.opt_Cert_Type = 1 Then
    Me.opt_Export_Domestic.Visible = True
ElseIf Me.opt_Cert_Type = 2 Then
    Me.opt_Export_Domestic.Visible = True
End If
End Sub

Private Sub opt_Export_Domestic_Click()
If Me.opt_Export_Domestic = 1 Then
    Me.opt_PMA_ASSY.Visible = True
ElseIf Me.opt_Export_Domestic = 2 Then
    Me.opt_PMA_ASSY.Visible = True
ElseIf Me.opt_Export_Domestic = 3 Then
    Me.opt_PMA_ASSY.Visible = True
End If
End Sub

This all forces the user to select from the option groups in a order which can be controlled by having the option groups become visible only after a selection has been made in the option groups one wishes to be picked from first, thus allowing some conditional things to be programmed with the knowledge that the user will be selecting things in a specific order...(in my case I have one option group that populates certain controls with different information based on which selection is made in one of the other option groups)

This is likely not the most elegant solution to achieve my goal, but it works quite well. Any constructive criticism would be warmly welcomed. :D Thanks again Missinglinq!!
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 13:34
Joined
Sep 12, 2006
Messages
15,613
to be honest, i really wouldn't try to force my users to pick/process option groups in a certain order.

you can either set the option groups to have a default setting, or not. If not, then no item is selected in the option group

now, assuming you have a command button to do something, in there you can just have a single set of tests for all the option groups

Code:
if nz(optiongroup1,0)=0 then
 msgbox "no choice sleectedi n option group 1"
 exit sub
end if

etc


if you still really want to set them to work only in a particular order then set the enabled property of the inactive ones to false.

then in the AFTERUPDATE event for optiongroup1
put optiongroup2.enabled = nz(optiongroup1,0)>0

then in the AFTERUPDATE event for optiongroup2
put optiongroup3.enabled = nz(optiongroup2,0)>0

etc.

note that if you do this, you cant really have a default setting, as you actively need to click a value to get the afterupdate event to fire
 

Users who are viewing this thread

Top Bottom