Compile Error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to programmatically obtain a list of users. Getting a compile
error with the following function obtained from FAQ

Function faq_ListUsersInSystem ()
Dim ws As WorkSpace
Dim i As Integer

Set ws = DBEngine.Workspaces(0)
For i = 0 To ws.Users.count - 1
Debug.Print ws.Users(i).Name
Next i
End Function
 
I am trying to programmatically obtain a list of users. Getting a compile
error with the following function obtained from FAQ

Function faq_ListUsersInSystem ()
Dim ws As WorkSpace
Dim i As Integer

Set ws = DBEngine.Workspaces(0)
For i = 0 To ws.Users.count - 1
Debug.Print ws.Users(i).Name
Next i
End Function

Do you have a reference to the Microsoft DAO library? You can check by opening the VB Edit window (Alt + F11) and
clicking Tools - References.

Also, it's usually a good idea to qualify your variables when possible:

Dim ws As DAO.WorkSpace

Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 
Thank you Scott

Changing Dim ws As WorkSpace to
Dim ws As DAO.WorkSpace

allowed the function to compile.

I have now found that it does not result in a print out. I am trying to
allow a user to print out the list of users in the attached workgroup file by
simply clicking a button. I do not want them to open the workgroup
administrator. Do you have any suggestions?
 
Thank you Scott

Changing Dim ws As WorkSpace to
Dim ws As DAO.WorkSpace

allowed the function to compile.

I have now found that it does not result in a print out. I am trying to
allow a user to print out the list of users in the attached workgroup file by
simply clicking a button. I do not want them to open the workgroup
administrator. Do you have any suggestions?

Your function would print the users to the Immediate window ... is this what you want, or do you want to show it on a
Form?

To show it on a form, add a Listbox named lstUsers to your form, and set the RowSourceType to "Value List", then run
this function:

Function faq_ListUsersInSystem ()
Dim ws As WorkSpace
Dim i As Integer
Dim strUser As STring

Set ws = DBEngine.Workspaces(0)
For i = 0 To ws.Users.count - 1
strUsers = ws.Users(i).name & ";" & strUsers
'Debug.Print ws.Users(i).Name
Next i

Me.lstUsers.RowSource = strUsers

End Function


Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 
Scott, thanks again for responding.

I would like the user to click a button that would produce the same report
and have the same action as when you would select the following:

Tools
Security
User and Group Accounts
Print Users and Groups command button on the Users tab
Only Users option
Ok command button

Is this possible?
 
Thanks for responding Scott.

I would like the user to click a button and get the same results obtained
from the Menu Bar you select

Tools
Security
User and Group Accounts
Print User and Group (Command Button on the Users Tab)
Only Users Option
OK

Is this possible?
 
Thanks for responding Scott.

I would like the user to click a button and get the same results obtained
from the Menu Bar you select

Tools
Security
User and Group Accounts
Print User and Group (Command Button on the Users Tab)
Only Users Option
OK

Is this possible?
 
Scott,

Thank you for responding.

My goal is to have the user click a button that would have the same results
as:

Tools
Security
User and Group Accounts
Print Users and Group (Command Button on the Users Tab)
Option Only Users
OK

Can this be accomplished?
 
Scott, thanks again for responding.

I would like the user to click a button that would produce the same report
and have the same action as when you would select the following:

Tools
Security
User and Group Accounts
Print Users and Groups command button on the Users tab
Only Users option
Ok command button

Is this possible?

You can use the various File I/O commands to print something like this, or you could dump this info to a table and build
a report on that table.

A better method might be to simply allow the user to use the builtin commands. You can build a custom toolbar/menubar
that allows them to view this toolbar (or portion of toolbar) so they can print this report. Assuming you've setup
security properly, they wouldn't be able to manipulate any settings.

To use standard File I/O, do something like this:

Function faq_ListUsersInSystem ()
Dim ws As DAO.WorkSpace
Dim usr As DAO.User
Dim i As Integer
Dim j as Integer
Dim strUser As STring
Dim lngFile As Long

'/open your text file
lngFile = FreeFileHandle
Open "Full path" For Output As #lngFile
Print #lngfile, Now
Print #lngFile, "--------------------------------------------------"
Print #lngFile, ""
Print #lngFile, "Users"
Print #lngFile, ""

Set ws = DBEngine.Workspaces(0)

For i = 0 To ws.Users.count - 1
Set usr = ws.Users(i)
strUsers = ws.Users(i).Name & vbTab
For j = 0 to usr.Groups.Count -1
'/now get a list of the Groups
strUsers = strUsers & usr.Groups(j).Name & ","
Next j
Print #nlgFile, strUsers
Next i

'/now do the same thing with Groups ... I'll leave that up to you

Close #lngFile
End Function


Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 
Back
Top