GK in the UK
Registered User.
- Local time
- Today, 17:40
- Joined
- Dec 20, 2017
- Messages
- 281
Does anyone know the syntax to get the Option Name, and the Option Button Tag, from the selected option in an Option Group ?
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
Select Case fraPurchIndexOptions.value
Case 1
txtDocType = "PINV"
Case 2
txtDocType = "PPAY"
Case 3
txtDocType = "SINV"
Case 4
txtDocType = "SRCT"
End Select
That does not address the question asked. That simply provides a return value.I've been using a Case Select like this
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?I've been using a Case Select like this:
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 withCode:Select Case fraPurchIndexOptions.value Case 1 txtDocType = "PINV" Case 2 txtDocType = "PPAY" Case 3 txtDocType = "SINV" Case 4 txtDocType = "SRCT" End Select
So, I want to put 'PINV' in the tag and just have code that says something like:
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...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>
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.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
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.There will be a lot more options to deal with
Isn't that more or less what I said?My solution works.
Yes.Isn't that more or less what I said?
Ahh. NO.
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.That's why I didn't try it out I thought it couldn't be done