rituarora
asked on
Differentiate between menu and sub-menu
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
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
ASKER
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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