Link to home
Start Free TrialLog in
Avatar of Petrobras
PetrobrasFlag for United States of America

asked on

Option Group need to make default to not check

Hello, I have an unbound option group (has a radio button) and I need it to default to "not checked" when the form is opened.  It seems to always remeber my last choice and I do not need this.  I have an "On Load" event of the following but it still does not default to not checked.  I triedd "False", "No", -1, 0 but still to no avail.   Any ideas? or does it have to be bound?   thank you
Private Sub Form_Load()
   
    Me.OptionGroupedSynBilat = False
    Me.OptionNotGrouped = False
   
End Sub
Avatar of IainTheVBALearner
IainTheVBALearner

Look at the properties of the option group.  Set it's Default Value number to 0 to make it so no option buttons in that group are checked.

Make sure when you add the buttons to the group directly from the Toolbox toolbar - so they're properly associated with each other.
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Try this:

Private Sub Form_Load()
   
    Me.OptionGroupedSynBilat = Null
    Me.OptionNotGrouped = Null
   
End Sub

mx
Avatar of Petrobras

ASKER

Hello Lain, DBmx:  I tried both to no avail.  I set default values to 0 for all option group radio buttons.  I also added tried to Null code.  The form is a pop up and I also tried to put the Null code on "On Open".  The radio buttons still "remember" my last choice  when opening the form.  

any other ideas?  thank you.
Hi Petrobras,
Long time no see! Hope everything is going well for you.  
The way I do it is to:
1. place an option button in the location you want to park it
2. set the button's option value to zero and set its visible property set to no.
3. set the default value for the OptionGroup to 0
4.In code, I usually have a select case statement and park at the  0 button after a selection is as shown:
Select Case Me.optGroupName.Value
       Case xxxx

       Case xxxx

End Select
Me.optGroupName = 0
Hi Mx,
Good to see you around!

pDog
SOLUTION
Avatar of IainTheVBALearner
IainTheVBALearner

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi pdog, good to hear from you again. I am trying to implement your idea but need some extra help.  First of all I want to say that it is not an option "group" but instead option buttons (radio buttons).  Knowing this, your #3:  set the default value for the OptionGroup to 0, I dont think applies.  But what do I know...not much.

I know I said it was an option group and I seem to remember that maybe there is a difference between group and stand alone buttons.  Maybe now since it is know that these are not option "groups" it changes it all.  maybe they should be option groups too but not sure how to make em.  

also, sorry but I am not sure what to put for the "xxx".  

Let me know...pb
lain, I see your post now.  I will try to add the group...
RATS!  I made the frame (have not done one in awhile).  But after clciking the option, it says "You entered an expression that has no value".  I followed the wizard in the option group.  
My code below for the frame:  
It is my lamens code and I know there is a better way to do it.  
See any issues here:  (I also tried =1, 0, -1 50, 5million a billion...etc...)  Now, I am just shooting the finger at the computer.  
Private Sub Frame7_Click()
   
    If Me.OptionGroupedSynBilat.Value = True Then
        DoCmd.OpenReport "rptPortfolioBilatSyn", acViewReport, , , acNormal
        Me.Visible = False
    End If
    If Me.OptionNotGrouped.Value = True Then
            DoCmd.OpenReport "rptPortfolio", acViewReport, , , acNormal
            Me.Visible = False
    End If
       
    If Me.OptionUsagePercent.Value = True Then
            DoCmd.OpenReport "rptPortfolioUsageSort", acViewReport, , , acNormal
            Me.Visible = False
    End If
   
End Sub
yes, as lain said, you need to add the group and place your buttons inside the group, otherwise the buttons will not work in team fashion.  xxx in the case statement are the different options corresponding to the object of interest in the Select Case statement.  You can have numbers Like Case 1, Case 2, etc. or you can have text like the example below:
 
Select Case Me.OptionColors.Value
Case "Blue"
       Do Something
Case "Yellow"
        Do Something else
End Select
Petrobras,
I have to go now, but I wanted to give you an idea of the syntax you can use.  I may have some errors because I did it off the top of my head without looking at anything to check it.

Private Sub Frame7_Click()
Select Case True
         Case 1
                  DoCmd.OpenReport "rptPortfolioBilatSyn", acViewReport, , , acNormal
                  Me.Visible = False
         Case 2
                    DoCmd.OpenReport "rptPortfolio", acViewReport, , , acNormal
                    Me.Visible = False
          Case 3
                    DoCmd.OpenReport "rptPortfolioUsageSort", acViewReport, , , acNormal
                    Me.Visible = False
End Select
     Me.OptionGroupFrame = 0                ' park button at default parking space
AHH...I see what the case is now.  I will give this a whirl in just a min.  
Hmm... would I be right in thinking that the problem occurs not when you open the form, but when you move from record to record? If so, you need to put your code on the OnCurrent event rather than OnLoad.
Calpurnia,
<the problem occurs not when you open the form, but when you move from record to record?
I do not have code anywhere else but on the
Private Sub Frame7_Click()
Select Case True
         Case 1
...........
I replaced the On load with the Private Sub Frame7_Click()
Could you just try putting your original code

    Me.OptionGroupedSynBilat = False
    Me.OptionNotGrouped = False

on the OnCurrent event of the form?
Calpurnia, and others: SORRY!  I think I had some kind of issue with the internet.  I asked another question but it did not post.  I wrote the question and pressed send but something happened and your last post made me think that we were not on the same page.  

The issue I have now is no matter what radio button I press, only the first report opens in case 1.  The names of the reports are correct so it is not a naming issue.  The values of the option buttons are correct at:  1,2,3.  I will be at the computer for awhile now.  thank you

Private Sub Frame7_Click()
   
 Select Case True
         Case 1
                  DoCmd.OpenReport "rptPortfolioBilatSyn", acViewReport, , , acNormal
                  Me.Visible = False
         Case 2
                  DoCmd.OpenReport "rptPortfolio", acViewReport, , , acNormal
                  Me.Visible = False
         Case 3
                  DoCmd.OpenReport "rptPortfolioUsageSort", acViewReport, , , acNormal
                  Me.Visible = False
End Select
     Me.Frame7 = 0                ' park button at default parking space
End Sub

Petrobras,
Just got back.  Have not had a chance to look it up yet..but try :
Case = 1     'use equal sign

or this:
Case Is 1     'use the word "Is"
puppydog:  I tried case = 1 and case is 1 and still did not correct the report opening to only case 1 issue.
(Access automatically changes Case is 1 to Case is = 1)
any other ideas?
Try it this way:
Private Sub Frame7_Click()
Dim iRpt As integer   '<<<<<<<<<<<<<<dim a variable
 Select Case True
         Case iRpt = 1             '<<<<use it in the expression

         Case iRpt = 2
----------------------------------
if "=" does not work, use "Is ="
puppydog:  Hmmm...that did not work either.  Actually, after making that change rt above, I could not click a radio button at all.  There was no action at all and no report opening.

what next?
change: Select Case True

To:
Select Case iRpt.Value
When I debug, I get an invalid qualifier error and it highlights the iRpt
this is how I have it:
Option Compare Database
Private Sub Frame7_Click()
   
Dim iRpt As Integer   '<<<<<<<<<<<<<<dim a variable
 Select Case iRpt.Value
         Case iRpt = 1
                  DoCmd.OpenReport "rptPortfolioBilatSyn", acViewReport, , , acNormal
                  Me.Visible = False
         Case iRpt = 2
                  DoCmd.OpenReport "rptPortfolio", acViewReport, , , acNormal
                  Me.Visible = False
         Case iRpt = 3
                  DoCmd.OpenReport "rptPortfolioUsageSort", acViewReport, , , acNormal
                  Me.Visible = False
End Select
     Me.Frame7 = 0                ' park button at default parking space
End Sub

I think I know what the problem is: you need to reference your optionframe 7 name, not iRpt

Select Case True
           Frame7 =  1
It now gives an error of "Statements and labels invalid between Select Case and first case"
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
and highlights Frame7 in Frame7 = 1
is Frame7 the name of your option group?
Change :
Select Case True   >>>>>  Select Case Frame7.Value
that was it!  Worked perfectly.  thank you so much.  
Petrobras,
Glad we got it sorted out.  I just plum forgot about the button connection.....sorry!  Thanks for your patience, and the points and grade.