Differentiate between menu and sub-menu

rituarora
rituarora used Ask the Experts™
on
I have a VB program which have multiple menu items and submenu items. Behind this I have a database which tells me the user wise sub-menu permissions. My query is whenever I login I need to have all my main menus to be enabled by default and all my sub-menus to become enable / disable depending upon the option. How do I accomplish this using programs. I have written the following code :
For Each cntrl In Me
If TypeOf cntrl Is Menu Then
Set adoPermission = New Recordset
adoPermission.Open "Select * from menuoptions m,     userpermission u " & _
" where m.app_id = u.app_id and m.menu_id =  u.menu_id  and m.app_id = '" & gApp & "' " & _
" and user_level = " & sngUserLevel & " and menu_name = '" & cntrl.Caption & "' ", adoconERES, adOpenKeyset, adLockOptimistic
If adoPermission.RecordCount = 0 Then
   cntrl.enabled = false
Else
    cntrl.Enabled = True
End If
End If
Next

cntrl.enabled = false is giving me error message.

Pl help
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Just a try for you. This is to allocate righs to the user correct. So have a table say X with Field Y for Menu and Z for the user.
Store the menu names in the table for which there are no rights along with the corresponding user name.

Now do this
Dim rs as new adodb.recordset
Dim Cnn as new adodb.connection
Cnn.ope n "Your path"
For each ctl in form
    if typeof ctl is menu then
       rs.open "Select * from X where Y = '" & ctl.name & "' and Z = '" & Username & "'",cnn,adopenkeyset, adlockoptimistic
       if rs.recordcount <> 0 then
         ctl.enabled = true
       else
         ctl.enabled = false
       end if
       rs.close
   End if
Next

Hope this code helps u

Author

Commented:
If you have read my question the I have written exactly the same code which you have mentioned. I have also mentioned that while I am setting cntl.enabled = false, VB gives me run time error :'Enabled' property cannot be set to this control
Sorry, but the above code works. see the following
I have a form with One Main Menu. Name - MnuFile and caption - File. One Sub Menu. Name - MnuRead and caption - read
in the load event of the form i have written the following code

Dim ctl As Control
For Each ctl In Form1
    If TypeOf ctl Is Menu Then
        If ctl.Name = "MnuRead" Then
            ctl.Enabled = False
        Else
            ctl.Enabled = True
        End If
    End If
Next

This works without any problem. Check whether u have declared the required.
Sorry if iam wrong
Good Luck...

Author

Commented:
I am sorry to respond back so late. Infact the problem got sorted out. I realised the error was coming only on those bars where separator was provided.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial