Solved Option group values visibility (1 Viewer)

ahmad_rmh

Member
Local time
Today, 23:54
Joined
Jun 26, 2022
Messages
243
I have an option group as under

Frame1:

Received
Returned to supplier
Stock Transfer
Transfer Return
Expired / Damaged Inventory
Adjustments

with values 1 to 6,

I have three case statements working as under as an open args

Receipt
Transfer
Adjustments

===============

I want one line code for option group values visibility as per the case

for example

for Receipt case

1st two values of option group should have to be visible, after 2 to 6 visibility false

for Transfer case

3 to 5 values visibility

for adjustment case

only 6 value should have to visible

================================

how to get the one line code.
 

Ranman256

Well-known member
Local time
Today, 16:54
Joined
Apr 9, 2015
Messages
4,337
Code:
select case frame1.value
    case 1
      txtBox1.visible = true
    case 2
      txtBox1.visible = false
      txtBox2.visible = true
    case 3
      txtBox1.visible = true
      txtBox2.visible = false

     'etc
end select
 

ahmad_rmh

Member
Local time
Today, 23:54
Joined
Jun 26, 2022
Messages
243
I am already doing like this but i have 6 values so want to make short
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:54
Joined
May 21, 2018
Messages
8,529
Easiest way to do this IMO
Tag all of the options with the cases where they are visible
Example Opt1 is visible for Receipt and Transfer then tag it "Receipt Transfer"

Code:
  Me.opt1.Visible = InStr(Me.opt1.Tag, me.openargs) > 0
  Me.opt2.Visible = InStr(Me.opt2.Tag, me.openargs) > 0
  Me.opt3.Visible = InStr(Me.opt3.Tag, me.openargs) > 0

I highly doubt anyone can code this in a single line of code. And for what
possible reason you need this in one line of code?
 

ahmad_rmh

Member
Local time
Today, 23:54
Joined
Jun 26, 2022
Messages
243
thanks @MajP, I have not tried before tag property.

I try it, if there is any reading article then let me know please.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:54
Joined
May 21, 2018
Messages
8,529
Every control has a Tag property, so it is often used to hold some information about the control. Often used to create groups of controls. In this case I use it to store the cases where it should be visible. I would use the search feature on this forum to try to find other threads using the control's tag.
 

Cronk

Registered User.
Local time
Tomorrow, 06:54
Joined
Jul 4, 2013
Messages
2,772
Use enabled for the option selections to grey out some of the options but keep them visible

Code:
select case me.openargs
   case is = "Receipt"
      me.option1.enabled = true
      me.option2.enabled = true
      me.option3.enabled = false
      me.option4.enabled = false
      me.option5.enabled = false
      me.option6.enabled = false
      
    case is = "Transfer"
      me.option1.enabled = false
      me.option2.enabled = false
      me.option3.enabled = true
      me.option4.enabled = true
      me.option5.enabled = true
      me.option6.enabled = true
      
    
etc
 

ahmad_rmh

Member
Local time
Today, 23:54
Joined
Jun 26, 2022
Messages
243
Is there any way like as under

Code:
If Frame.Enabled = True then

Frame.Value > 2

The frame value greater than 2 for case "Receipt" should be false.

But how to do
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:54
Joined
May 21, 2018
Messages
8,529
Is there any way like as under

Code:
If Frame.Enabled = True then

Frame.Value > 2

The frame value greater than 2 for case "Receipt" should be false.

But how to do
As written that does not make any sense, so NO. I think what I suggested is six lines of code so shorter than the other suggestions and easier to code.
 

ahmad_rmh

Member
Local time
Today, 23:54
Joined
Jun 26, 2022
Messages
243
Thanks Maj, i have tried but could not implemented because lack of proper information and study.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:54
Joined
May 21, 2018
Messages
8,529
Here is as short as I can make the code regardless of how many options you have. You could have 50 options and 50 open args and the code is still four lines.
Code:
Dim ctrl As Access.Control
  For Each ctrl In Me.Controls
    If InStr(ctrl.Tag, Me.OpenArgs) > 0 Then ctrl.Visible = True
  Next

Default all options to visible = false. Tag all options.
 

Attachments

  • Options.accdb
    412 KB · Views: 85

ahmad_rmh

Member
Local time
Today, 23:54
Joined
Jun 26, 2022
Messages
243
Here is as short as I can make the code regardless of how many options you have. You could have 50 options and 50 open args and the code is still four lines.
Code:
Dim ctrl As Access.Control
  For Each ctrl In Me.Controls
    If InStr(ctrl.Tag, Me.OpenArgs) > 0 Then ctrl.Visible = True
  Next

Default all options to visible = false. Tag all options.

thanks a lot Maj, 🌹🌹🌹
done and resolved,
the shortest way for all cases, so not required to write in all cases separately.
 

ahmad_rmh

Member
Local time
Today, 23:54
Joined
Jun 26, 2022
Messages
243
Now I am facing another problem, I have made a search form to go on a specific record through list box. It's working but option group is missing.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:54
Joined
May 21, 2018
Messages
8,529
It's working but option group is missing
The way it is set up is all options are hidden until you pass an openargs. If you do not pass one they stay hidden. Here is new code to unhide if no openargs
Code:
Private Sub Form_Load()
  Me.Text2 = Me.OpenArgs
  Dim ctrl As Access.Control
  If (Me.OpenArgs & "") <> "" Then
  For Each ctrl In Me.Controls
    If InStr(ctrl.Tag, Me.OpenArgs) > 0 Then ctrl.Visible = True
  Next
  Else
    'Make all options visible
    For Each ctrl In Me.Controls
      If ctrl.ControlType = acOptionButton Then ctrl.Visible = True
    Next ctrl
  End If
End Sub
 

ahmad_rmh

Member
Local time
Today, 23:54
Joined
Jun 26, 2022
Messages
243
The way it is set up is all options are hidden until you pass an openargs. If you do not pass one they stay hidden. Here is new code to unhide if no openargs
Code:
Private Sub Form_Load()
  Me.Text2 = Me.OpenArgs
  Dim ctrl As Access.Control
  If (Me.OpenArgs & "") <> "" Then
  For Each ctrl In Me.Controls
    If InStr(ctrl.Tag, Me.OpenArgs) > 0 Then ctrl.Visible = True
  Next
  Else
    'Make all options visible
    For Each ctrl In Me.Controls
      If ctrl.ControlType = acOptionButton Then ctrl.Visible = True
    Next ctrl
  End If
End Sub

thanks a lot Maj. 🌹 🌹 🌹
 

Users who are viewing this thread

Top Bottom