Results 1 to 9 of 9
  1. #1
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    368

    Gat Caption


    I want to get the label caption after clicking in an option group
    I've typed it into each controls shortcut menu and get it back by
    Code:
     Select Case Frame0
            Case 1
                Target = Option3.ShortcutMenuBar
            Case 2
                Target = Option5.ShortcutMenuBar
            Case 3
                Target = Option7.ShortcutMenuBar
            Case 4
                Target = Option9.ShortcutMenuBar
        End Select
    But I have this nagging doubt this is stupid and I should not need Select Case ( or shortcutMenu)
    Can I get the labels caption directly by clicking it's option button ?

  2. #2
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,655
    try this after changing the option button name to one of yours

    Code:
    Me.Option15.Controls.Item(0).Caption
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  3. #3
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    368
    Would I still need that instruction once for each Option button?
    You cannot get the one clicked directly from the Frame ?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,954
    If you name buttons to coincide with value they pass to frame, like Option1, Option2, then:

    Me.Controls("Option" & Me.Frame0).Controls.Item(0).Caption
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,818
    Not sure if I've interpreted that sentence but AFAIK, you cannot directly determine which option button in a group/frame is selected, so no.
    You could code (perhaps a Select Case block) using the frame value to determine the chosen button.

    Code:
    Select Case Me.Frame1
      Case 1
         do something
      Case 2
         do something else
      Case...
    End Select
    Those "do somethings" would be to code as shown to get the caption.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,954
    Micron, isn't OP already doing that? Think I provided an alternative.

    What I don't understand is "typed into each controls shortcut menu"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,818
    Micron, isn't OP already doing that? Think I provided an alternative.

    What I don't understand is "typed into each controls shortcut menu"
    Well, I don't think so but since I don't understand that either, who knows? I'm saying get the "selected" control first by association with the frame value. I don't see what Target and shortcut menu has to do with that, but maybe it's because it's something I've never seen before. I have created shortcut menus (and the old style of menus) but this seems to be something else.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    368
    I entered the control name into properties shortcut menu.
    Then I could get it into variable 'Target" as per msg 1
    But Junes suggestion worked great and now I don't need the select case.
    Thank you.

  9. #9
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,655
    You can also use a function to return the selected option button label, provided you use the default option button values (ie. 1,2,3,4, etc)

    Code:
    Function OGBLabel(fr As OptionGroup) As String
        Dim ctl As Control
        Dim strCaps As Variant
    
        For Each ctl In fr.Controls
            If ctl.ControlType = acOptionButton Then
                strCaps = strCaps & ctl.Controls.Item(0).Caption & ","
            End If
        Next
    
        strCaps = Left(strCaps, Len(strCaps) - 1)
    
        OGBLabel = Split(strCaps, ",")(fr.value - 1)
    
    End Function
    Last edited by moke123; 11-21-2022 at 01:50 PM.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

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

Similar Threads

  1. Replies: 15
    Last Post: 11-03-2015, 12:48 AM
  2. Caption for the form or report
    By kpalar in forum Forms
    Replies: 1
    Last Post: 08-01-2014, 07:44 AM
  3. Blink Caption
    By Naveen Marapaka in forum Forms
    Replies: 3
    Last Post: 09-18-2013, 10:33 PM
  4. Getting Value as label Caption
    By Naveen Marapaka in forum Forms
    Replies: 4
    Last Post: 09-18-2013, 12:22 AM
  5. VBA caption button of record
    By Ruegen in forum Forms
    Replies: 4
    Last Post: 08-19-2013, 05:03 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