Using Password Changer for Admins

J

Jonathan Brown

I'm attempting to use a Password Changer for Admins form
that I downloaded and imported into my front end DB.

While I try to compile the code it gives me an error
message that says, "Compile error: User-defined type not
defined". I click okay and it's highlighted a statement
in the code that says: Dim ws As Workspace

If I comment the line out and attempt to compile again it
then highlights the next line of code that says: Dim
TempUser As User

If I comment that line out, then the same thing happens
for the following line of code that says: Dim TempGroup As
Group

Apparently I need to define what a "Workspace" is and
a "User" and "Group" are.

The code is included below:

Private Sub RefreshUserList_Click()
Dim J As Integer
Dim strRowSource As String
Dim strTempUser As String
Dim ws As Workspace
Dim TempUser As User
Dim TempGroup As Group

On Error GoTo ERRREFRESHUSERLIST

DoCmd.Hourglass True

Set ws = DBEngine.Workspaces(0)
Set TempGroup = ws.Groups("Users")
TempGroup.Users.Refresh

strRowSource = ""

For J = 0 To TempGroup.Users.Count - 1

Set TempUser = TempGroup.Users(J)

Select Case TempUser.Name
Case "Creator", "Engine", "Admin"
If Me!HideDefaultUsers = 0 Then strRowSource =
strRowSource & "'" & TempUser.Name & "';'" & J & "';"
Case Else
strRowSource = strRowSource & "'" &
TempUser.Name & "';'" & J & "';"
End Select

Next J

Me!UserList.RowSource = strRowSource
Me!UserList.Requery

ws.Close

DoCmd.Hourglass False

Exit Sub

ERRREFRESHUSERLIST:
ws.Close
DoCmd.Hourglass False
MsgBox "An error occured while populating the list of
users: " & Error$, vbCritical
Exit Sub

End Sub
 
M

MikeC

Jonathan,

Sounds like you just need to select a "Microsoft DAO 3.6
Object Library" in Tools/References. Give it a try and
then recompile afterwards.
 
J

Jonathan Brown

Great! thanks MikeC. The code is compiling now without a
hitch. Although there's still one problem though. When I
open the form, the userlist still does not display any of
the users I've defined in my database and the mouse turns
into an hourglass and never goes away unless I close the
DB and go back in. It looks like it's trying to refresh
the userlist but it can't pull anything for some reason.
Any ideas there?
 
J

Jonathan Brown

Well, I've done a few things now and the Hourglass has
gone away. But I'm still stuck. I'm going to include my
code below again to show the changes I've made. What's
happening now is when I open the form, or when I trigger
the RefreshUserList_click() subroutine by clicking
the "Refresh List" button I get an error message that
says "An error occured while populating the list of users:
The setting for this property is too long". I don't know
what setting it's talking about otherwise I'd probably try
to make it shorter somehow. I click okay to clear the
error message and my form still doesn't show anyone in my
user list.

Thanks for all the help I'm getting.
 
G

Guest

I forgot to include the code. Here it is:

Private Sub RefreshUserList_Click()

Dim J As Integer
Dim strRowSource As String
Dim strTempUser As String
Dim ws As Workspace
Dim TempUser As User
Dim TempGroup As Group

On Error GoTo ERRREFRESHUSERLIST

DoCmd.Hourglass True

Set ws = DBEngine.Workspaces(0)
Set TempGroup = ws.Groups("Users")
TempGroup.Users.Refresh

strRowSource = ""

For J = 0 To TempGroup.Users.Count - 1

Set TempUser = TempGroup.Users(J)

Select Case TempUser.Name
Case "Creator", "Engine", "Admin"
If Me!HideDefaultUsers = 0 Then strRowSource =
strRowSource & "'" & TempUser.Name & "';'" & J & "';"
Case Else
strRowSource = strRowSource & "'" &
TempUser.Name & "';'" & J & "';"
End Select

Next J

Me!UserList.RowSource = strRowSource
Me!UserList.Requery

ws.Close

DoCmd.Hourglass False

Exit Sub

ERRREFRESHUSERLIST:
ws.Close
DoCmd.Hourglass False
MsgBox "An error occured while populating the list of
users: " & Error$, vbCritical
Exit Sub

End Sub
 
M

MikeC

Jonathan,

OK, I got it working in my test database.

For the Me!UserList combo box, I set the properties as
follows:

Row Source Type = Value List
Column Count = 2
Column Widths = 1";1"

If you have not already done the above, then you will need
to do so.

I made a few minor changes to the code, but I don't see
how any of these changes would have fixed your error. I'm
guessing that the above property settings were the key.

Private Sub RefreshUserList_Click()
On Error GoTo ERRREFRESHUSERLIST

Dim J As Integer
Dim strRowSource As String
Dim strTempUser As String
Dim ws As DAO.Workspace 'Added "DAO." just to be
extra clear.
Dim TempUser As User
Dim TempGroup As DAO.Group 'Added "DAO." just to be
extra clear.

DoCmd.Hourglass True

Set ws = DBEngine.Workspaces(0)
Set TempGroup = ws.Groups("Users")
TempGroup.users.Refresh

strRowSource = ""

For J = 0 To TempGroup.users.Count - 1
Set TempUser = TempGroup.users(J)
Select Case TempUser.Name
Case "Creator", "Engine", "Admin"
If Me!HideDefaultUsers = 0 Then
strRowSource = strRowSource & "'" &
TempUser.Name & "';'" & J & "';"
End If
Case Else
strRowSource = strRowSource & "'" &
TempUser.Name & "';'" & J & "';"
End Select
Next J

Me!UserList.RowSource = strRowSource
Me!UserList.Requery

Exit_RefreshUserList_Click:
On Error Resume Next
ws.Close 'I moved these items down
here.
DoCmd.Hourglass False
Exit Sub

ERRREFRESHUSERLIST:
MsgBox "An error occured while populating the list of
users: " & Error$, vbCritical
Resume Exit_RefreshUserList_Click

End Sub
 
J

Jonathan Brown

MikeC,

I appreciate all the help you're giving me. I think I've
found out what the problem is. What I did is I exported
my form to a new blank test database and then secured it
and created a few test usernames. So now with a new
Secured.mdw file and different usernames in a blank
database the form worked perfectly. This leads me to
believe that my secured.mdw file is corrupted somehow. So
my question now is, is there a way that I can validate all
the data in my secured.mdw file to correct any problems in
it?

Jonathan
 

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