Option Frame: Get Name and Tag text (1 Viewer)

GK in the UK

Registered User.
Local time
Today, 14:32
Joined
Dec 20, 2017
Messages
274
Does anyone know the syntax to get the Option Name, and the Option Button Tag, from the selected option in an Option Group ?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:32
Joined
Oct 29, 2018
Messages
21,357
Hi. It depends on where you put the tag. The frame itself has a tag. The radio buttons have their own tags. And the labels for those buttons have yet their own tags. Typically, I would just use a Select Case statement to work with the option selected. What exactly are you trying to accomplish?


PS. I forgot to ask, which Name are you trying to get? The button, the label, something else?
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:32
Joined
May 21, 2018
Messages
8,463
Code:
Private Sub Frame0_AfterUpdate()
  Dim ctrl As Access.Control
  For Each ctrl In Me.Frame0.Controls
    If ctrl.ControlType = acOptionButton Then
      If ctrl.OptionValue = Me.Frame0.Value Then
        MsgBox ctrl.Controls(0).Caption ' prints caption of associated label
        MsgBox ctrl.Tag & " " & ctrl.Name 'print tag of selected option
      End If
    End If
  Next ctrl
End Sub
Might be easier way
 

GK in the UK

Registered User.
Local time
Today, 14:32
Joined
Dec 20, 2017
Messages
274
I've been using a Case Select like this:

Code:
Select Case fraPurchIndexOptions.value
    Case 1
        txtDocType = "PINV"
    Case 2
        txtDocType = "PPAY"
    Case 3
        txtDocType = "SINV"
    Case 4
        txtDocType = "SRCT"
End Select
But I had a similar situation with a tab control, with a big CASE SELECT and when I changed the code to get some information from the tag it massively improved the code. There will be a lot more options to deal with

So, I want to put 'PINV' in the tag and just have code that says something like:

txtDocType = <current option selection tag>
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:32
Joined
May 21, 2018
Messages
8,463
I've been using a Case Select like this
That does not address the question asked. That simply provides a return value.
 

GK in the UK

Registered User.
Local time
Today, 14:32
Joined
Dec 20, 2017
Messages
274
I've called the buttons optPINV, optPPAY, optSINV, and optSRCT


So if I could get the name of the button I could parse what I need from there


But I see there is a 'tag' property for the button so if I just put PINV in the tag for the button I wouldn't need the Case Select


The case select could be replaced with the single line
txtDocType = <current option selection tag>
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:32
Joined
May 21, 2018
Messages
8,463
Ahh. NO.

Extras characters.
Extras characters.
Extras characters.
Extras characters.
Extras characters.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:32
Joined
Oct 29, 2018
Messages
21,357
I've been using a Case Select like this:

Code:
Select Case fraPurchIndexOptions.value
    Case 1
        txtDocType = "PINV"
    Case 2
        txtDocType = "PPAY"
    Case 3
        txtDocType = "SINV"
    Case 4
        txtDocType = "SRCT"
End Select
But I had a similar situation with a tab control, with a big CASE SELECT and when I changed the code to get some information from the tag it massively improved the code. There will be a lot more options to deal with

So, I want to put 'PINV' in the tag and just have code that says something like:

txtDocType = <current option selection tag>
Hi. I think I remember helping you with that one. Was it in this thread? Unfortunately, Tab Controls are a little different than Option Groups. Have you considered using a Combobox instead?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:32
Joined
Oct 29, 2018
Messages
21,357
I've called the buttons optPINV, optPPAY, optSINV, and optSRCT

So if I could get the name of the button I could parse what I need from there

But I see there is a 'tag' property for the button so if I just put PINV in the tag for the button I wouldn't need the Case Select

The case select could be replaced with the single line
txtDocType = <current option selection tag>
The problem is the value of an option group doesn't directly map to the button like a tab page does in a tab control. If you continue in this route, I'm afraid you may simply be replacing your Select Case block with a For Each loop. It might work, but it may end up being the same amount of work in the end. Just a thought...
 

GK in the UK

Registered User.
Local time
Today, 14:32
Joined
Dec 20, 2017
Messages
274
Yes, that's the thread. If it can't be done I'll just stick with the Case Select, it's just a single assignment in each case this time. Thanks again
 

Micron

AWF VIP
Local time
Today, 10:32
Joined
Oct 20, 2018
Messages
3,476
So if I could get the name of the button I could parse what I need from there
But I see there is a 'tag' property for the button so if I just put PINV in the tag for the button I wouldn't need the Case Select
I don't get what's the problem with the solution in post 3? For the selected option it gives the control name and the tag property. The only thing that might be iffy is if a label isn't attached/associated then it will err. That's easy enough to prevent.
There will be a lot more options to deal with
then why favour a Select Case block over a loop? 20 options, 20 Case statements - or the same number of loop statements whether it's 1 or 20.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:32
Joined
May 21, 2018
Messages
8,463
My solution works.
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:32
Joined
May 21, 2018
Messages
8,463
Isn't that more or less what I said?
Yes.
..................................................................................................................................................... Extra lines.......................................
 

GK in the UK

Registered User.
Local time
Today, 14:32
Joined
Dec 20, 2017
Messages
274
Yes you're right MajP's solution does work and does what I want. I should have followed it up properly, and I like it better than the multiple case statements.


That's why I didn't try it out I thought it couldn't be done

Thanks MajP
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:32
Joined
May 21, 2018
Messages
8,463
That's why I didn't try it out I thought it couldn't be done
FYI, I rarely post non working code, and if I do I preface with "Untested" or "try something like.." If it could not be done, I would tell you.
 

Users who are viewing this thread

Top Bottom