Solved VBA code to Disable multiple selection of commands (1 Viewer)

alvingenius

IT Specialist
Local time
Today, 02:05
Joined
Jul 10, 2016
Messages
169
Hello
i'm having a form with alot of Buttons
and i've a group of buttons i wanna enable/disable them via VBA based on userID logged

i can use
Code:
if ******* then
Me.command1.enabled=false 
else
Me.command1.enabled=true
end if

but i'll have to repeat it with the number of buttons

a simple demo of db attached , please apply code there !!

thanks

EDIT:
The working sample db in this post

Explanation :
in form, u must put a tag on all controls then the group of controls you wanna control together with another tag
then you use the module in the attached db in the post mentioned above and the procedure in buttons too

Thanks @isladogs for your time and effort applying code to this sample file
Thanks @Gasman, your very small letters made me understand the way it worked in Colin's database
Thanks @arnelgp, for providing an advanced way of doing this
 

Attachments

  • Database1.accdb
    400 KB · Views: 106
Last edited:

isladogs

MVP / VIP
Local time
Today, 01:05
Joined
Jan 14, 2017
Messages
18,209
What exactly don't you understand about my example app?
It uses the Tag property to enable/disable (etc) a group of controls at the same time.
So for example if the first two buttons form one group and the other two buttons are a second group then you assign the same tag value to each member of the two groups. Assuming the Tag values chosen are A and B then add code to the Form_Load event something like this

Code:
If UserId =…. Then
EnableControls True, "A"
EnableControls False, "B"
Else
EnableControls False, "A"
EnableControls True, "B"
End if
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:05
Joined
May 7, 2009
Messages
19,231
here is a sample that you might want to study.
there is no login form but the principle are the same.
check out tblObjectAccess, also the code behinde the form.
 

Attachments

  • sample.zip
    26.4 KB · Views: 109

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:05
Joined
May 21, 2018
Messages
8,525
One format you can use is something like this instead of if then else
Code:
me.someControl.enabled = (something.value = "****")
me.somecontrol2.enabled = (something.value = "something")
....
me.somecontrolN.enabled = (something.value = "something else")

If the right side returns true or false then the left side resolves to enabled or disabled.
 

alvingenius

IT Specialist
Local time
Today, 02:05
Joined
Jul 10, 2016
Messages
169
I'm sorry i'm not that good in Access to understand that yet

i'm attaching a simple db, can you please apply a simple code for it ?

Thanks
 

Attachments

  • Database1.accdb
    400 KB · Views: 118

isladogs

MVP / VIP
Local time
Today, 01:05
Joined
Jan 14, 2017
Messages
18,209
Alvin
You've had 4 suggestions on ways of implementing this.
Its not clear who you are addressing here or what you've attempted as your example contains no code.
Its also not clear (to me at least) what you want to happen on your form.

Suggest you try one or more methods, then post your attempts with specific questions aimed at the appropriate person.
 

Mark_

Longboard on the internet
Local time
Yesterday, 17:05
Joined
Sep 12, 2017
Messages
2,111
alvingenius,
If you are only trying to cut down on typing, you can set all buttons to be disabled when the form opens. You then add one sub that enables only those buttons needed for the user.

Are you trying to do by user or by role security?
 

alvingenius

IT Specialist
Local time
Today, 02:05
Joined
Jul 10, 2016
Messages
169
Well

as mentioned before

i'm not that good in coding with DB

i need a clear code to understand !!

One format you can use is something like this instead of if then else
Code:
me.someControl.enabled = (something.value = "****")
me.somecontrol2.enabled = (something.value = "something")
....
me.somecontrolN.enabled = (something.value = "something else")

If the right side returns true or false then the left side resolves to enabled or disabled.

i don't understand what is that !!

What exactly don't you understand about my example app?
It uses the Tag property to enable/disable (etc) a group of controls at the same time.
So for example if the first two buttons form one group and the other two buttons are a second group then you assign the same tag value to each member of the two groups. Assuming the Tag values chosen are A and B then add code to the Form_Load event something like this

Code:
If UserId =…. Then
EnableControls True, "A"
EnableControls False, "B"
Else
EnableControls False, "A"
EnableControls True, "B"
End if

i've tag A and Tag B set
and i get that error


here is a sample that you might want to study.
there is no login form but the principle are the same.
check out tblObjectAccess, also the code behinde the form.

it did the trick but That's a long way to do that and i've to change the way i build the app
thanks


Alvin
You've had 4 suggestions on ways of implementing this.
Its not clear who you are addressing here or what you've attempted as your example contains no code.
Its also not clear (to me at least) what you want to happen on your form.

Suggest you try one or more methods, then post your attempts with specific questions aimed at the appropriate person.

read this post
and i've attached a simple demo i did to understand what will happen on it

what i want in my db is when i click on a button it disable a group of buttons or check boxes in one time without going to code disable for every button or checkbox
 

Attachments

  • tag.PNG
    tag.PNG
    11.9 KB · Views: 378

Gasman

Enthusiastic Amateur
Local time
Today, 01:05
Joined
Sep 21, 2011
Messages
14,231
I can't open Colin's DB as I only have 2007, but the links states

To use this approach, just copy the module modControlState to your own project

Then just use the syntax supplied.

Have you done that.?
 

alvingenius

IT Specialist
Local time
Today, 02:05
Joined
Jul 10, 2016
Messages
169
I can't open Colin's DB as I only have 2007, but the links states

To use this approach, just copy the module modControlState to your own project

Then just use the syntax supplied.

Have you done that.?

i did that i've set Tag B to group of checkboxs and used the syntax in disable button and it disabled all buttons and checkboxes while i mentioned only B tag
all buttons and every control don't have a tag on form disabled
how to only limit action to only tag i've mentioned !?

 

Attachments

  • enable.PNG
    enable.PNG
    66.3 KB · Views: 361
Last edited:

alvingenius

IT Specialist
Local time
Today, 02:05
Joined
Jul 10, 2016
Messages
169
I've done a trick
to Select all Controls and Tag em with : 0 then the group of controls i want to : A
then it disabled only A and left all controls with other tags
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:05
Joined
May 7, 2009
Messages
19,231
you are doing it manually, I thought it was based on the user's access?
 

isladogs

MVP / VIP
Local time
Today, 01:05
Joined
Jan 14, 2017
Messages
18,209
@Alvin 'genius'

See attached for a working version of your simple database
Form1 - top button enables the bottom controls, second button disables them.
The top two buttons have a different tag value to ensure those aren't disabled by the code.

I've added a new Form2 showing how the same button can be used to enable or disable the remaining controls
Please study the code carefully to make sure you understand it.

In future, please actually try the code suggested rather than expecting people to do it all for you

For the benefit of other forum members, in what area are you an IT specialist?
 

Attachments

  • Database1_v2_CR.accdb
    400 KB · Views: 103

alvingenius

IT Specialist
Local time
Today, 02:05
Joined
Jul 10, 2016
Messages
169
@Alvin 'genius'

See attached for a working version of your simple database
Form1 - top button enables the bottom controls, second button disables them.
The top two buttons have a different tag value to ensure those aren't disabled by the code.

I've added a new Form2 showing how the same button can be used to enable or disable the remaining controls
Please study the code carefully to make sure you understand it.

In future, please actually try the code suggested rather than expecting people to do it all for you

For the benefit of other forum members, in what area are you an IT specialist?

Thank you
and i've already did that understanding the code and i've posted already the trick that i'm stucking at

Thanks again
 

isladogs

MVP / VIP
Local time
Today, 01:05
Joined
Jan 14, 2017
Messages
18,209
It really wasn't clear whether you had got it working or were stuck.
I notice you didn't answer my question!

In future please follow the advice given in my last post or you may find people will stop bothering to suggest answers.

In addition, a lot of us have contributed many responses to your security question. Perhaps you could respond to that thread at some point
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:05
Joined
Sep 21, 2011
Messages
14,231
you are doing it manually, I thought it was based on the user's access?

I think the o/p is trying to get it working in a simple way, before trying to apply it to the real system.?
 

Users who are viewing this thread

Top Bottom