G
Gwen
Please help.
The query result depends on the group account(s) that the
user is member of.
Some users belong to more than one group
I think I am close but not quite there.
The record count is 1 when it should be 559.
What am I doing wrong?
Sub getuser()
Dim usr As User
Dim strusername As String
Dim varname As String
Dim strcriteria As String
Dim grpname As String
Dim strsql As String
Dim i As Integer
Dim somenum as Integer
Dim ws As Workspace
Dim db As Database
Dim rst As Recordset
Set ws = DBEngine.Workspaces(0)
strusername = CurrentUser
Set db = CurrentDb
Set usr = ws.Users(strusername)
varname = "(table.[somefield])"
strcriteria = "(table.[somefield])"
For i = 0 To usr.Groups.Count - 1
grpname = usr.Groups(i).Name
strcriteria = strcriteria & "= """ & grpname & """ or "
strcriteria = strcriteria & varname
Next i
strcriteria = Left$(strcriteria, Len(strcriteria) -
somenum)
strsql = "SELECT * from table"
strsql = strsql & " WHERE(" & strcriteria & ");"
Debug.Print strsql
Set rst = db.OpenRecordset(strsql)
Debug.Print rst.RecordCount
db.Close
Set db = Nothing
End Sub
The query result depends on the group account(s) that the
user is member of.
Some users belong to more than one group
I think I am close but not quite there.
The record count is 1 when it should be 559.
What am I doing wrong?
Sub getuser()
Dim usr As User
Dim strusername As String
Dim varname As String
Dim strcriteria As String
Dim grpname As String
Dim strsql As String
Dim i As Integer
Dim somenum as Integer
Dim ws As Workspace
Dim db As Database
Dim rst As Recordset
Set ws = DBEngine.Workspaces(0)
strusername = CurrentUser
Set db = CurrentDb
Set usr = ws.Users(strusername)
varname = "(table.[somefield])"
strcriteria = "(table.[somefield])"
For i = 0 To usr.Groups.Count - 1
grpname = usr.Groups(i).Name
strcriteria = strcriteria & "= """ & grpname & """ or "
strcriteria = strcriteria & varname
Next i
strcriteria = Left$(strcriteria, Len(strcriteria) -
somenum)
strsql = "SELECT * from table"
strsql = strsql & " WHERE(" & strcriteria & ");"
Debug.Print strsql
Set rst = db.OpenRecordset(strsql)
Debug.Print rst.RecordCount
db.Close
Set db = Nothing
End Sub