I have the following code:
Public Function mm(mname As String)
On Error GoTo errhand
'If ingroup("Activity") Then mname = "Activity Tracking Menu"
Dim lb As Integer, cnt As Integer, op As Form, rstmenu As DAO.Recordset, bend As Integer
Set dbsmed1 = CurrentDb()
Set rstmenu = dbsmed1.OpenRecordset("SELECT * FROM menu WHERE (((menu.[menu name])='" & mname & "'));", dbOpenDynaset, dbReadOnly)
rstmenu.MoveLast
rstmenu.MoveFirst
If Not IsLoaded("opening2") Then DoCmd.OpenForm "opening2", acNormal, , , , acHidden
If rstmenu.RecordCount < 22 Then
Set op = Forms![opening1]
Forms![opening2].Visible = False
Forms![opening1].Visible = True
bend = 21
Else
Set op = Forms![opening2]
Forms![opening1].Visible = False
Forms![opening2].Visible = True
bend = 28
End If
op.Caption = mname
op![Menu Name].Caption = mname
op![Command1].SetFocus
With rstmenu
Do While Not .EOF
op("label" & ![button #]).Visible = True
op("command" & ![button #]).Visible = True
op("label" & ![button #]).Caption = ![button label]
op("command" & ![button #]).ControlTipText = Nz(![button help])
lb = ![button #] + 1
.MoveNext
Loop
End With
For cnt = lb To bend
op("label" & cnt).Visible = False
op("command" & cnt).Visible = False
Next
Close
'Stop
Exit Function
errhand:
MsgBox (Err & " " & Err.Description & " mm")
'Stop
'Resume
End Function
Public Function ingroup(strgrp As String, Optional strusr As String) As Boolean
Dim wrkDefault As Workspace
Dim grp As Group
Dim usrloop As user, grploop As Group
If strusr = "" Then strusr = Application.CurrentUser
' Get default workspace.
Set wrkDefault = DBEngine.Workspaces(0)
With wrkDefault
Set grp = .Groups(strgrp)
' Stop
ingroup = False
If grp.Users.count <> 0 Then
For Each usrloop In grp.Users
If usrloop.name = strusr Then ingroup = True
Next usrloop
End If
End With
' Stop
End Function
If the user belongs in group 'Activity' I need to change the menu. So I added the following (in comments above):
If ingroup("Activity") Then mname = "Activity Tracking Menu"
If I run it with this line enabled, I get the following error:
Run Time Error 3265 - Item not found in this collection mm.
If I run it with:
mname = "Activity Tracking Menu" (without the if)
it works fine.
Also I think there is something wrong with the Ingroup function, because the usrloop only looks at the first user and the leaves the loop.
As always all help is greatly appreciated.
Sarah
Selasa, 07 Agustus 2012
[MS_AccessPros] Please help me with this code
__._,_.___
.
__,_._,___
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar