davencharleston 12-19-2003, 07:58 AM I get the Item Not Found In Collection Error at the beginning of this line:
For Each grp In DBEngine.Workspaces(0).Users(CurrentUser).Groups
I am using DAO and Access 2002. What did I do wrong?
Thanks,
David
00100b 12-19-2003, 08:10 AM Is CurrentUser a variable? If so of what data type and what is its value.
The error is stating the a User object in the Users collection doesn't exist with either the specified Key or Index value.
davencharleston 12-19-2003, 08:15 AM Is CurrentUser a variable? If so of what data type and what is its value.
The error is stating the a User object in the Users collection doesn't exist with either the specified Key or Index value.
CurrentUser is a string which represents the current user
if I wrote Msgbox CurrentUser, the msgbox would display the username of the currentuser. CurrentUser is a DAO function.
00100b 12-19-2003, 08:18 AM Try capturing the results of the CurrentUser method call to a string variable and passing the string variable as the argument in the Users collection.
davencharleston 12-19-2003, 08:26 AM Try capturing the results of the CurrentUser method call to a string variable and passing the string variable as the argument in the Users collection.
i just did but i get the same error.
workspaces(0) refers to the default workspace right? i mean, i haven't created a workspace anywhere in my code.
davencharleston 12-19-2003, 08:39 AM by the way,
i basically want to find out which groups the current user belongs to and and set some boolean values accordingly. if you can think of a way that does this, i'm all ears.
thanks,
david
00100b 12-19-2003, 08:43 AM Yes, Workspaces(0) refers to the default workspace.
I just ran this test:
Public Function Foo()
Dim objGroup As Group
For Each objGroup In DBEngine.Workspaces(0).Users(CurrentUser).Groups
Debug.Print objGroup.Name
Next
Set objGroup = Nothing
End Function
And it displayed the names of the two groups that the CurrentUser is a member of.
Are you performing this from within Access itself or from a VB interface to the Access MDB?
davencharleston 12-19-2003, 08:44 AM Are you performing this from within Access itself or from a VB interface to the Access MDB?
i am performing this in Access in a module that has all global variables. i'll try your solution and write back if it doesn't work.
THANKS SO MUCH!
davencharleston 12-19-2003, 08:50 AM i tried your solution.
ok i get the same darn error.
i can't figure it out.
00100b 12-19-2003, 08:54 AM In the Immediate Window, if you type
?DBEngine.Workspaces(0).Name
and press the Enter key, do you get a line stating something like:
#Default Workspace#
davencharleston 12-19-2003, 08:55 AM In the Immediate Window, if you type
?DBEngine.Workspaces(0).Name
and press the Enter key, do you get a line stating something like:
#Default Workspace#
when i hit enter in the code window,
?DBEngine.Workspaces(0).Name
gets replaced immediately with Print DBEngine.Workspaces(0).Name
davencharleston 12-19-2003, 08:56 AM In the Immediate Window, if you type
?DBEngine.Workspaces(0).Name
and press the Enter key, do you get a line stating something like:
#Default Workspace#
when i hit enter in the code window,
?DBEngine.Workspaces(0).Name
gets replaced immediately with Print DBEngine.Workspaces(0).Name
then i get compile error: method not valid without suitable object
i put that line of code in the foo function
00100b 12-19-2003, 08:57 AM No, in the Immediate Window. Add the Debug toolbar (by right-clicking on the toolbar and selecting Debug), and then click on the Immediate Window icon. In that window, enter the ?... and then hit enter.
davencharleston 12-19-2003, 08:58 AM In the Immediate Window, if you type
?DBEngine.Workspaces(0).Name
and press the Enter key, do you get a line stating something like:
#Default Workspace#
when i hit enter in the code window,
?DBEngine.Workspaces(0).Name
gets replaced immediately with Print DBEngine.Workspaces(0).Name
then i get compile error: method not valid without suitable object
i put that line of code in the foo function
ok, i just do a msgbox and when i run the code i do get #default workspace#
davencharleston 12-19-2003, 09:00 AM OK, figured out the whole immediate window thing
00100b 12-19-2003, 09:00 AM For this "Testing" stuff, you might want to use the Immediate Window. It's easier for this.
Now in the Immediate Window type:
?DBEngine.Workspaces(0).Users.Count
and press enter. What is the value?
davencharleston 12-19-2003, 09:01 AM For this "Testing" stuff, you might want to use the Immediate Window. It's easier for this.
Now in the Immediate Window type:
?DBEngine.Workspaces(0).Users.Count
and press enter. What is the value?
7 which is correct
davencharleston 12-19-2003, 09:05 AM For this "Testing" stuff, you might want to use the Immediate Window. It's easier for this.
Now in the Immediate Window type:
?DBEngine.Workspaces(0).Users.Count
and press enter. What is the value?
7 which is correct
actually, i only count 6 users including Admin (5 other than Admin)
00100b 12-19-2003, 09:06 AM To minimize this back and forth, I'm going to just put a bunch of tests here. For each Immediate Window (code block) below, report your results please (whether an error and what the error is, or if you got the expected result. I don't need to know the actual values).
1.
?CurrentUser
2.
Paste the following function into your Module
Public Function Foo2()
Dim objUser As User
For Each objUser In DBEngine.Workspaces(0).Users
Debug.Print objUser.Name
Next
Set objUser = Nothing
End Function
And in the Immediate Window type Foo2 and press enter.
3. For this one, hand-type in the value returned by the CurrentUser above.
?DBEngine.Workspaces(0).Users(<current user value>).Groups.Count
davencharleston 12-19-2003, 09:12 AM To minimize this back and forth, I'm going to just put a bunch of tests here. For each Immediate Window (code block) below, report your results please (whether an error and what the error is, or if you got the expected result. I don't need to know the actual values).
1.
?CurrentUser : dhenley (correct)
2.
Paste the following function into your Module
Public Function Foo2()
Dim objUser As User
For Each objUser In DBEngine.Workspaces(0).Users
Debug.Print objUser.Name
Next
Set objUser = Nothing
End Function
And in the Immediate Window type Foo2 and press enter.
result:
admin
Creator
dhenley
ebutler
Engine
mharper
progers
(correct i guess but i have never seen Creator or Engine before)
3. For this one, hand-type in the value returned by the CurrentUser above.
?DBEngine.Workspaces(0).Users(<current user value>).Groups.Count
result:
error Item not found in this collection
runtime error 3265
i am also part of the admin group so...
davencharleston 12-19-2003, 09:19 AM 3. For this one, hand-type in the value returned by the CurrentUser above.
?DBEngine.Workspaces(0).Users(<current user value>).Groups.Count
[/QUOTEPOST]
instead of
?DBEngine.Workspaces(0).Users(dhenley).Groups.Count
I tried
?DBEngine.Workspaces(0).Users("dhenley").Groups.Count
with result 2
but i get invalid argument when i try and run the function
00100b 12-19-2003, 09:31 AM Let's alter Foo2 to the following:
Public Function Foo2()
Dim objUser As User
Dim objGroup As Group
For Each objUser In DBEngine.Workspaces(0).Users
Debug.Print objUser.Name
If objUser.Name = "dhenley" Then
For Each objGroup In objUser.Groups
Debug.Print objGroup.Name
Next
End If
Next
Set objGroup = Nothing
Set objUser = Nothing
End Function
What are the results?
davencharleston 12-19-2003, 09:38 AM you wouldn't believe me if i told you, but i've used
dim currentusr as string
currentUsr = CurrentUser
For Each grp In Workspaces(0).Users(currentUsr).Groups
and it works fine. i don't know why...
i appreciate your help. if nothing else, i know about the immediate windown and debugging now.
THANKS!!!
00100b 12-19-2003, 09:40 AM I'm sorry, but isn't that what I asked you to try back in the 4th post of this thread?
Try capturing the results of the CurrentUser method call to a string variable and passing the string variable as the argument in the Users collection.
davencharleston 12-19-2003, 09:42 AM I'm sorry, but isn't that what I asked you to try back in the 4th post of this thread?
Try capturing the results of the CurrentUser method call to a string variable and passing the string variable as the argument in the Users collection.
it is, but it didn't work then for some reason. like seriously.
davencharleston 12-19-2003, 09:46 AM well i thought it was working but i still can get that error.
i asked the guy who helped me originally and he said the if you use workspace(0) too early, access will not have had time to open it.
however, my code doesn't error out during the immediate window,
BUT does error out and give the wrong answer when i run the form.
i don't know. i guess i can keep plugging away. thanks for all of your help.
|