473,385 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Dim or Disable specific sub-menu items using VBA?

NeaPa,

Following code in used for disable sub-menu items for specified user. The problem I am having is one of below user is not able see it (Mean disabled the sub-menu items) I want both of them to see sub-menu when they currently on database. Any there is anything wrong with this code which causing one user unable to use sub-menu items.

Expand|Select|Wrap|Line Numbers
  1. Dim blnShow As Boolean
  2.  
  3.     blnShow = Nz(StrComp(Me.MyName, "aman", vbTextCompare), True) = False
  4.     With CommandBars("MyMenu").Controls(1)
  5.         .Controls(1).Enabled = blnShow
  6.         .Controls(2).Enabled = blnShow
  7.         .Controls(3).Enabled = blnShow
  8.     End With
  9.  
  10.     blnShow = Nz(StrComp(Me.MyName, "Ram", vbTextCompare), True) = False
  11.         With CommandBars("MyMenu").Controls(1)
  12.         .Controls(1).Enabled = blnShow
  13.         .Controls(2).Enabled = blnShow
  14.         .Controls(3).Enabled = blnShow
  15.     End With
Prompt help appreciated
Thanks a lot
Oct 31 '11 #1
3 2481
MikeTheBike
639 Expert 512MB
Hi

On the basis that strComp returns 0 (zero) when the match is found (seem the wrong way round to me - never used it before) then for two users as indicated I suggest this

Expand|Select|Wrap|Line Numbers
  1. Dim blnShow As Boolean
  2.  
  3. blnShow = Nz(StrComp(MyName, "aman", vbTextCompare), True) And Nz(StrComp("Ram", "aman", vbTextCompare), True)
  4.  
  5. With CommandBars("MyMenu").Controls(1)
  6.     .Controls(1).Enabled = blnShow
  7.     .Controls(2).Enabled = blnShow
  8.     .Controls(3).Enabled = blnShow
  9. End With
??

For more than two users I would have a lookup table in the back end and use DLookUp(), or more probably DCount() to deal with the Null case, to determine who cannot use the menu item.

MTB
Oct 31 '11 #2
MTB,

Thanks a lot for sharing. I have already resolved this task, The following has been used instead of earlier one and working perfect

Expand|Select|Wrap|Line Numbers
  1.     Select Case Me.MyName
  2.     Case "aman"
  3.         With CommandBars("MyMenu").Controls(1)
  4.             .Controls(1).Enabled = True
  5.             .Controls(2).Enabled = False
  6.             .Controls(3).Enabled = False
  7.         End With
  8.  
  9.         With CommandBars("MyMenu").Controls(2)
  10.             .Controls(1).Enabled = True
  11.             .Controls(2).Enabled = True
  12.  
  13.         End With
  14.  
  15.     Case "Ram"
  16.         With CommandBars("MyMenu").Controls(1)
  17.             .Controls(1).Enabled = True
  18.             .Controls(2).Enabled = True
  19.             .Controls(3).Enabled = False
  20.         End With
  21.     End Select
Thanks a lot for again sharing
Oct 31 '11 #3
NeoPa
32,556 Expert Mod 16PB
If you have two (multiple) users then use InStr() instead :
Expand|Select|Wrap|Line Numbers
  1. Dim blnShow As Boolean
  2.  
  3. blnShow = (InStr(1, ";aman;ram;", ";" & Me.MyName & ";", vbTextCompare) > 0)
  4. With CommandBars("MyMenu").Controls(1)
  5.     .Controls(1).Enabled = blnShow
  6.     .Controls(2).Enabled = blnShow
  7.     .Controls(3).Enabled = blnShow
  8. End With
NB. Don't forget the separators (I used semi-colons (;) in this case) as otherwise you may find a user called "ama" is matched in error.
Oct 31 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: ZubZero | last post by:
Hello, i have to write a utility in c++ for windows 2k/XP. But i have 2 difficult problems. I asked many programmers i know, but none of them was able to tell me how i can do this. 1. I...
1
by: Hemal2k | last post by:
To disable specific key in IE and Firefox Solution :- //call ValidateInvalidCharacters(event); function from form body.... <body onkeypress="ValidateInvalidCharacters(event);" leftMargin="0"...
2
by: tottigang | last post by:
Hi, I have a tabstrip and I have some tabs in it. On the first page, all the tabs are enabled, I need to disbale part of the tabs at a specific point in the application and again enable them. I...
1
by: alex | last post by:
Hi, is there an easy way to disable (prevent from edit) specific rows in a datagrid ? Alex
2
by: Brian Henry | last post by:
I want to time how long a specific sub takes to execute, what is the best way to do this? this is only for one sub, and i just need a result back in milliseconds or such to display to a user....
5
by: Tanja Krammer | last post by:
Hi experts, is it possible to disable linker warnings (i.e. LNK4204)? Thanx
7
by: tommaso.gastaldi | last post by:
It would be useful, sometimes, when debugging, to disable all the try /catch one has in the program (clearly not commenting them out). Any info or hint on that? -tom
2
by: badkarspiloten | last post by:
Hi there! I have just migrated from VS 2003 to VS 2005 and are getting lots of compile warnings when building my solution. Some of them I want to disable. I have managed to do this with my...
3
by: Bob Alston | last post by:
Anyone know how to disable or redefine the Ctrl - hotkey which deletes a record? I have a multi page form that uses 14 records, each record handles 1-2 pages of the 18 page form. Occasionally ,...
2
by: ValValVal | last post by:
Hi all. I have a JTable with 5 columns. Cell Selection is ON. I want to disable user's ability to select any cell that is on 0-th column. Can't find any info on how to cope with it. Thanks in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.