Results 1 to 12 of 12
  1. #1
    llgtjb001 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Sep 2015
    Posts
    33

    I have a problem with option group's code.


    Click image for larger version. 

Name:	Option Group.png 
Views:	10 
Size:	9.6 KB 
ID:	22162
    As you see in the image, I have three options groups. When I check No of G and Yes of B, the ER option will be enabled( I choose enabled false on ER).
    Code:
    Private Sub frER_Click()
    
    Dim lblNo1 As Boolean
    Dim lblYes2 As Boolean
    
    
    
    
    
    
        If lblNo1.Checked = True And lblYes2.Checked = True Then
            frER.Enabled = True
            Else
            frER.Enabled = False
            End If
            
    End Sub
    After I type the code, it does not work. How could I fix it?
    Thank you.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I do not recall if you can make more than one selection within an option group. I do not believe you can. The idea behind the Radio Button is when you select one, any previous selection reverts. In an Option Group, the value of the Option Group is what is used.

    You need to determine the name of your option group. You can select your Option Group by clicking it or swooping with your cursor. You need to be careful to not select a radio button. Swooping the outer edge of the option group usually works best for me. With the option group selected, you can view the name of the option group within the properties sheet.

    So you would evaluate the value of your option group
    Code:
    If Me.OptionGroupName.Value = 1 Then
    'Do this
    ElseIf Me.OptionGroupName.Value = 2 Then
    'Do something else
    else
    'This should happen
    End if

  3. #3
    llgtjb001 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Sep 2015
    Posts
    33
    Thank you for your reply. I try to fix it.
    Code:
    If Me.frG.Value = 2 And Me.frBrand.Value = 3 Then        frER.Enabled = True
            Else
            frER.Enabled = False
            End If
    It still not work. Do I need to dim any value?

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Did you use the Wizard to create your Option Group? What ever the value is of the selected Radio Button, will be the value of your Option Group. You can look at the properties of a Radio Button to make sure they are not all Option Value = 1

    One Radio Button should have Option Value = 1 and another should have Option Value = 2.

    Perhaps you should start by testing one of the Option Groups.

    In the AfterUpdate event of frG, you could place the following code and then test frG while in Form View.

    Code:
    msgbox Me.frG.Value

  5. #5
    llgtjb001 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Sep 2015
    Posts
    33
    Code:
    Private Sub frER_Click()
    
    
    
    
    
    
    
        If Me.frG.Value = 2 And Me.frBrand.Value = 3 Then
            frER.Enabled = True
            Else
            frER.Enabled = False
            End If
            
    End Sub
    Still not work.

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Why are you using this Event?
    Code:
    Private Sub frER_Click()
    Does not seem like the code you have is ever going to be able to execute.

    Perhaps the AfterUpdate event of frG AND the AfterUpdate event of frBrand would be more appropriate.

  7. #7
    llgtjb001 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Sep 2015
    Posts
    33
    I think I use the form design and choose the option group. First group I set the ration button1 =1 and another =2. Then I set the second as 3 and 4, and third as 5 and 6.
    Click image for larger version. 

Name:	marco Optiongroup.jpg 
Views:	9 
Size:	32.8 KB 
ID:	22163
    also, where I can see the value of ration button? and how do I test it? Just type in
    Code:
    Private Sub frER_AfterUpdate()    
        MsgBox Me.frG.Value
        
    End Sub
    like this?

  8. #8
    llgtjb001 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Sep 2015
    Posts
    33
    I think I got it. Thank you I have to copy paste the code for both frG and frB. That will work.
    Because I am not sure which event that I should type in.

  9. #9
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I have to admit that I do not know what that screenshot is. If you are creating Macros, you should not be mixing VBA in the same event.

    The VBA you posted in post #7 will work. It will tell you the value of the Radio Button you select via a message box. It will also let you know that your code is working.

    If you want to look at the properties sheet, you can see the value of a Radio Button there, too. But the property sheet is not going to tell you whether or not your VBA code is executing.

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by llgtjb001 View Post
    ...
    Because I am not sure which event that I should type in.
    I suggest you use the AfterUpdate Event for both option groups that are being evaluated.

    AfterUpdate event of frG AND the AfterUpdate event of frBrand

  11. #11
    llgtjb001 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Sep 2015
    Posts
    33
    Do you mean to select the ration button to see the value? I do not find them. In which menu of properties?

  12. #12
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I know it can get confusing. There are different properties for different controls. If you select one of the two radio buttons within option group frG you can view its properties within the Properties Sheet. The Option Value property is under the data tab.

    If you use the VBA code you posted in post #7, you should expect a message box to display the same value as indicated in the Option Value property.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 10-03-2014, 06:36 AM
  2. Option Group
    By x__hoE__x in forum Access
    Replies: 2
    Last Post: 12-10-2011, 09:39 AM
  3. Dependent option group problem
    By Remster in forum Programming
    Replies: 5
    Last Post: 10-22-2010, 10:23 AM
  4. Option Group
    By huskies in forum Forms
    Replies: 9
    Last Post: 12-02-2009, 12:06 PM
  5. VB code for sending email through Option Group?
    By getdpt in forum Programming
    Replies: 0
    Last Post: 08-23-2009, 03:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums