Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239

    Question option group

    Okay, I tried to figure this one on me own but quite frankly it is taking too long. I have this code in the afterUpdate event of the first option groupA but it didn't work!



    What I want is, if the user selects "No" in optiongroup A, then option group B should be greyed out. If it cannot be greyed out, then it can be invisible. The user will have hundreds of records to enter and this will help them navigate faster.

    If Me.FrameA = "No" Then
    Me.FrameB.Visible = False
    Else
    Me.FrameB.Visible = True
    End If

    Click image for larger version. 

Name:	OptionGroup event.jpg 
Views:	28 
Size:	15.0 KB 
ID:	18388


  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    frame values are not strings. you have "NO"
    they are numeric so, its either
    0,1,2 (if thats what you set the option values to)

    I would hope No = 0.

  3. #3
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239
    ah yes. Should be 2.
    Option values are 1,2 & 3

    I'll try this. Thanks ranman.

  4. #4
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239
    thanks ranman. it worked but how can I make the frame greyed out instead of invisible

  5. #5
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239
    Questions:

    1) how can I make the option group as a whole greyed out?

    2) when I save the record, the form is cleared and ready for the next record but frames from the previous record are still invisible

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    1) A frame control has the Enabled property just like a text box control. So the code would look something like
    Code:
    Private Sub FrameA_AfterUpdate()
        If Me.FrameA = 2 Then
            Me.FrameB.Enabled = False
        Else
            Me.FrameB.Enabled = True
        End If
    
    
    
    '    Select Case Me.FrameA
    '        Case 0, 1    'Yes or Unknowm
    '            Me.FrameB.Enabled = True
    '
    '        Case 2    ' No
    '            Me.FrameB.Enabled = False
    '
    '    End Select
    End Sub
    For 3 or more options you could use the "Select Case" structure instead of the "IF..Else IF....End If" syntax.

    2) I would try putting the same code in the form current event. The frame should have the default property set to 2 (No).

  7. #7
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239
    Hey Steve, thanks much. It worked but how can I make the label "If Yes, what's the indication" greyed out as well...?

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    According to my tests, when the option group (FrameB) enabled property = False, the label is greyed out.

    I set the font color to Red for the label on "FrameB"..... the label turned gray when Enabled = False.

    You could change the label font color, (set the font color to be the same as the Background or to light grey)
    You could set the label Visible property to No,
    You could change the label caption property.

  9. #9
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239
    Many thanks Steve. Since the option group allows only one choice per group and my users want to choose more than one option in some cases, I manually assembled some check box controls and put a rectangle around them. Setting their individual "enabled" property to False leaves the label at the top untouched. That was the one I wanted greyed out. I forgot that there was no cohesiveness among the controls. I'll try the font colour change.

  10. #10
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239
    Okay, I tried this code but it is complaining of a Data Type mismatch and this line was highlighted

    Me.Label1041.ForeColor = "#B2A97A"

    If I remove the quotation marks, it highlights the "#" and says compiler error...

  11. #11
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Add this to a Standard Module:

    Code:
    Public Function HexColor(strHex As String) As Long
    
        'converts Hex string to long number, for colors
        'the leading # is optional
    
        'example usage
        'Me.iSupplier.BackColor = HexColor("FCA951")
        'Me.iSupplier.BackColor = HexColor("#FCA951")
    
        'the reason for this function is to programmatically use the
        'Hex colors generated by the color picker.
        'The trick is, you need to reverse the first and last hex of the
        'R G B combination and convert to Long
        'so that if the color picker gives you this color #FCA951
        'to set this in code, we need to return CLng(&H51A9FC)
        
        Dim strColor As String
        Dim strR As String
        Dim strG As String
        Dim strB As String
        
        'strip the leading # if it exists
        If Left(strHex, 1) = "#" Then
            strHex = Right(strHex, Len(strHex) - 1)
        End If
        
        'reverse the first two and last two hex numbers of the R G B values
        strR = Left(strHex, 2)
        strG = Mid(strHex, 3, 2)
        strB = Right(strHex, 2)
        strColor = strB & strG & strR
        HexColor = CLng("&H" & strColor)
    
    End Function

    Save the Module and name it HexColorConvert

    Now use this code

    Me.Label1041.ForeColor = HexColor("#B2A97A")

    I've had this code archived for several years, and sadly, do not have the name of the author.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  12. #12
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239
    many thanx Linq. I'll try this.

  13. #13
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I convert the hex color number to decimal using the manual method.

    In design view of the form, I change the color using the color picker.
    Then I write down the RGB values from the Custom Tab.
    If I will be using the color in many places in the code, I convert the RGB values to a Long using
    Code:
    Dim SomeVariable as Long
    Somevariable = RGB(178,169,122)  '(<= #B2A97A)
    msgbox SomeVariable  (8038834)   'so I can see the number
    I write down the value, then set a constant

    Code:
    Const GrayedOut as Long = 8038834
    .
    .
    Me.Label17.ForeColor = GrayedOut

    But I'm going to save the code example
    Thanks Linq

  14. #14
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239
    Hey thanks Steve


    Linq - I got run-time error 13" Type mismatch on this line of your code

    HexColor = CLng("&H" & strColor)



  15. #15
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    HexColor = CLng("&H" & strColor)
    That is not anything like what Linq wrote.

    The the argument for the function HexColor() is a hexadecimal number and returns a long integer. You can't declare a a variable the same name as the function.

    Code:
    Dim InactiveColor as Long
    InactiveColor = HexColor("#B2A97A")
    Me.Label1041.ForeColor =InactiveColor
    or
    Code:
        Dim strColor As String
    
        strColor = "#B2A97A"
    .
    .
    .
        Me.Label1041.ForeColor = HexColor(strColor)

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Option Group selection
    By mahmud1180 in forum Programming
    Replies: 4
    Last Post: 10-10-2014, 05:42 PM
  2. Replies: 4
    Last Post: 10-03-2014, 06:36 AM
  3. Option Group
    By x__hoE__x in forum Access
    Replies: 2
    Last Post: 12-10-2011, 09:39 AM
  4. Option Group
    By huskies in forum Forms
    Replies: 9
    Last Post: 12-02-2009, 12:06 PM
  5. Option Group broken out
    By dcecil in forum Reports
    Replies: 3
    Last Post: 04-21-2009, 10:30 AM

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