Rabu, 08 Agustus 2012

[MS_AccessPros] Re: Please help me with this code

 



Clive,
I am making the change but don't I need an 'end if' after the 'exit for'?
Also do you have any suggestion why I am getting the error 'Run Time Error 3265 - Item not found in this collection. mm' ?. It is only happening in compiled mode.

Thanks
Sarah

--- In MS_Access_Professionals@yahoogroups.com, "Clive" <zctek@...> wrote:
>
> Hi Sarah,
>
> There is a problem with your loop.
>
> In your code,
>
> If usrloop.name = strusr Then ingroup = True
> Next usrloop
>
> the loop is repeated for each value of name so
> you will get the correct result only if the user
> is the last entry in the list.
>
> Change it to,
>
> If usrloop.name = strusr Then
> ingroup = True
> Exit For
> Next usrloop
>
> Regards, Clive.
>
> --- In MS_Access_Professionals@yahoogroups.com, "novice012000" <sarahk@> wrote:
> >
> > 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
> >
>

__._,_.___
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar