Toggle Control (1 Viewer)

gakiss2

Registered User.
Local time
Today, 04:49
Joined
Nov 21, 2018
Messages
168
Private Sub Toggle36_Click()
Dim Toggle As Boolean
If Toggle = False Then
Toggle = True
Else: Toggle = True
End If

If Toggle = True Then
DoCmd.SelectObject acForm, CboSQEPicker
DoCmd.SetProperty CboSQEPicker, acPropertyVisible, 0
Else: DoCmd.SetProperty CboSQEPicker, acPropertyVisible, -1
End If




End Sub

I tried to find the answer on the magical Google machine but I think this one is so simple that all the solutions went way over what I wanted to do. I am a bit new but starting to get used to form controls but I had not yet used a toggle. I found a situation where it would be a good approach I think so I tried to program what I wanted but it didn't work. To me it seems I tried to reinvent the toggle but just don't know the right code to make it do what it is designed to do.

The behavior wanted is to push this button to turn of or off a control which should only be used by a supervisor. By on or off I was trying to simply use the 'visible' property. At this point I am not needing any real security, just encouraging users to leave that control alone unless they are a supervisor. Maybe later I can distinguish between a Supv user and a regular user and attach permissions but that is above my ability at this point. So I am trying to get the form to work on a basic level first then add these security bells and whistles later. I have the advantage of being very amateur so there are very low expectations for my performance as a MS Access crackerjack :). Your help is appreciated.
 

sxschech

Registered User.
Local time
Today, 04:49
Joined
Mar 2, 2010
Messages
792
Something like this?

Code:
Private Sub Toggle36_Click()
'Dim Toggle As Boolean
If me.toggle36 = False Then
me.toggle36 = True
me.cbosqepicker.visible=false
Else 
me.Toggle36 = True
me.cbosqepicker.visible=true
End If

End sub
 

isladogs

MVP / VIP
Local time
Today, 12:49
Joined
Jan 14, 2017
Messages
18,209
If I understand you correctly, when the toggle is true then CboSQEPicker should be hidden.
So I think this will work. Remove the Not if I've got it the wrong way round!

Code:
Private Sub Toggle36_Click()

    Me.CboSQEPicker.visible= Not Me.Toggle36

End sub
 

gakiss2

Registered User.
Local time
Today, 04:49
Joined
Nov 21, 2018
Messages
168
isladogs

Love the simplicity. I thought I was way overthinking it. so rather than SetProperty, I just call Me.controlname.property = True or False? And the value of togglecontrol is already true or false so that can be the expression after the '='.

Now on to other improvements.
 

Users who are viewing this thread

Top Bottom