Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to set menu properties programmatically at run time?

Status
Not open for further replies.

applek

Programmer
Nov 18, 2002
15
US
Hi.

There are existing menus inside the form. My program is to define which user has the right access to which menu. These information will be retrieved from a DAtabase.

For instance, i retrieve userID 123, who can only access menu1, menu2, menu3(the menu name of the form). Hence, i tell the program that the menu1, menu2 and menu3 to be set as enabled. In order to make the program dynamically, the collection method that i realized that is not so dynamic. If i use array method, can i directly assign the menu name (which retrieved from Database) to the object menu:

Redim arrItem (10) as menu

while not rs.eof
i = 0
arrItem(i) = rs.fields("Item") --(1)
arrItem.enabled = true
i = i +1
loop

(1) : this may cause a problem since the casting is not allowed

do you have any idea? pls help.
 

I am not sure that I understand exactly what you are saying but I think I have an idea, but let me make sure that I have what you are saying is correct.

You have menus that you want to be able to control the access to via a security schema that you have devisied.

These menus that you are controlling are in an array.

The permissions of access are stored in a database and you retrieve those permissions to be able to control the menus.

If this is so then (depending upon what type of field) you could do something like.
[tt]
Dim I As Integer
Do While Not Rs.Eof
menuItem(I).Enabled = Rs.Fields("Boolean_Field")
I = I + 1
Loop
[/tt]

Inversly if it is not a boolean field that contain the permissions you could test for good/bad-allowed/disallowed.

Now as I also understand it you have multiple forms that have these security driven menus on them. If this is so then you could save the permissions in a public boolean array and on load run through that array so you only need to go to the database once for the users permissions.

I hope this helps, Good Luck

 
Is this the same thing you were asking under:

thread222-408957

?? [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
I do something similar to what you have described. I have gone a little farther, perhaps, by allowing the menu options to be hidden as well (so an option can be completely hidden from users not authorized to use or see it). The only problem that I ran into in doing this (beyond the complexity of setting it all up) is that you aren't allowed to hid the last submenu option on a menu. I finally worked around that one by trapping the error and hiding the parent menu as well. That's a little bit trickier, but it works. I also devised a crude method of pulling the menu options from the form (at design time) to help populate that part of the database.

I know I didn't provide any "solutions" with this posting, but I wanted to let you know that you are not alone out there in trying to accomplish something that I think is very practical and important.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top