Results 1 to 4 of 4
  1. #1
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    No Value in Option Group (2002)

    Hi!

    I've been trying to use the option group control. I have two option buttons in an option box with a command button. If option 1 is selected than report A opens. Otherwise if option 2 is selected a Report B opens. I used and If/Elseif statement but get an error message that states that there hasn't been a value assigned to the button. The statment I used is as follows:

    If me.opt1 = true then
    docmd.openreport "rptA", acpreview
    Elseif me.opt2 = true then
    docmd.openreport "rptB", acpreview
    End if

    I thought that when I entered "true" I was assigning a value. What am I missing?

    Thanks,
    Alicia

  2. #2
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    Brookings, South Dakota, USA
    Posts
    449
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: No Value in Option Group (2002)

    Hi Alicia,
    It is the Option Group itself that has the value, not the Option buttons. The Group value will be a value of one of the Option buttons; i.e. if you have 2 Option Buttons Opt1 and Opt2 and the value of of Opt1 = 1, the value of Opt2 = 2 (they do not need to be numbers, but in keeping with your example I will use them) which are are set via the Option button property box....so your code should read:

    If Me!NameOfYourOptionGroup = 1 Then
    DoCmd.OpenReport "rptA", acPreview
    ElseIf Me!NameOfYourOptionGroup = 2 Then
    DoCmd.OpenReport "rptB", acPreview
    EndIf

    I find it is usually easier to use a Select Case when using an Option Group

    Select Case Me!NameOfYourOptionGroup
    Case 1
    DoCmd.OpenReport "rptA", acPreview
    Case 2
    DoCmd.OpenReport "rptB", acPreview
    End Select

    hth,
    gdr
    <IMG SRC=http://www.wopr.com/w3tuserpics/gdrezek_sig.jpg>
    "Those who dance are considered insane by those who can't hear the music" - George Carlin

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: No Value in Option Group (2002)

    An Option Group also has a default value property. If you have not set a default value and you have not clicked one of the buttons, then the option group has no value. The buttons themselves don't return a value in an option group, they simply have an assigned data value that is used to set the value of the option group when that button is clicked.
    Charlotte

  4. #4
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: No Value in Option Group (2002)

    Thank you! That worked great. I've never used select case before but used it here as per your suggestion/example.

    Leesha

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •