Security FAQ code problems

M

Matt Howard

I am using a code from the Security FAQ that verifies
whether or not a user is in a group to enable an object on
a form. It works in one database, but the other I get a
compile error saying the user-defined type was not
declared (more or less). Here is the code, word for word
from the FAQ in my database:

Function faq_IsUserInGroup(strGroup As String, strUser As
String) As Integer
' Returns true if user is in group, False otherwise
' This only works if you're a member of the Admins group
Dim ws As WorkSpace
Dim grp As Group
Dim strUserName As String

Set ws = DBEngine.Workspaces(0)
Set grp = ws.groups(strGroup)
On Error Resume Next
strUserName = ws.groups(strGroup).users(strUser).Name
faq_IsUserInGroup = (Err = 0)
End Function

There is nothing different from this database and my other
one. "Dim ws As WorkSpace" is the line that returns the
error.

Any help would be great.

Thanks,

Matt Howard
 
A

Albert D. Kallal

You need a references to the dao 3.6 library if using a2000 or later.

You might for future refs...add the above ref, and then quality your refs
like:

dim ws as dao.WorkSpace
 
T

TC

In addition to what the other respondent said:

The code that you quote, has an unused object (grp), and returns an Integer
instead of a Boolean. Also, there is no apparent reason why it would only
work for members of the Admins group. It should work for >any< user, so that
comment is incorrect.

Try:

Function faq_IsUserInGroup(strGroup As String, strUser As String) As Integer
' Returns true if user is in group, False otherwise.
dim s as string
on error resume next
s = dbengine(0).groups(strGroup).users(strUser).name
faq_IsUserInGroup = (Err = 0)
End Function

HTH,
TC
 
T

TC

Oops!
Function faq_IsUserInGroup(strGroup As String, strUser As String) As
BOOLEAN

I know that it might not make any difference in practice, but I can't see
any point in declaring the return value to be integer, when we know for sure
that it will be a true/false value.

TC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top