Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Login System Using Workgroups and "Currentuser" 1

Status
Not open for further replies.

gyli84

MIS
Aug 6, 2001
67
0
0
GB
I want to create a login system within Access for a helpdesk program I am creating but I need it to be able to:

1)Direct the user to a form dependent upon their access level (there will be a form for helpdesk users and a unique one for the helpdesk manager ie. 2 acess levels)
2)Store the user ID the user logged in with in a temporary table (known as a control table in Delphi) whilst they are logged in such that for example an object on the form could display the logged in user's name (a staff ID in the login table allows a relationship between it and a STAFF table to be made).

Someone has suggested that by using workgroups and user level security I can check the currentuser() and open an appropriate form by placing code on the form that is loaded (could be a menu or splash screen) after the username and password is entered. i.e. user enters username/password, use code to look at currentuser(), load appropriate form. The trouble is that I do not know how I could code this so that a form would open dependent upon whether they are an "administrator" with administrator level access or just a "user" had logged in and also so that the form could show the name of the person logged in (there would be nowhere in the workgroup file that would specify a relationship between the user id of the person logging in and their name, is it possible then?) Could anybody help!?

Thanks

 
Check out the following thread

Home > Forum Areas > Programmers > DBMS Packages > Microsoft: Access Forms Forum
Password / Login
thread702-112875
 
Hi!

Try my function for users permissions administration. It works successfuly in all my DBs. (You may create reference to DAO library for using this function)

Examples:
'This command set form's command button Enabled=True if CurrentUser is Admins group's member Enabled=False in oposite case.
Me.cmdOpenForm.Enabled = IsUserInGroup
or
'This commands allow to change form's data only to members of user groups AddWriteUsers or Admins

Dim blnAllow As Boolean
If IsUserInGroup or IsUserInGroup(, "AddWriteUsers") Then
blnAllow = True
end if
Me.AllowAdditions= blnAllow
Me.AllowDeletions= blnAllow
Me.AllowEdits= blnAllow

'------------------------------------

Public Function IsUserInGroup(Optional strUser As String = "", _
Optional strGroup As String = "") As Boolean
'Verify user's permissions
'If is omitted strUser (user name), CurrentUser is verified
'If is omitted strGroup (group name), user group "Admins" is verified

On Error GoTo Err_IsUserInGroup
Dim usr As User

If Trim(strUser) = "" Then strUser = CurrentUser
If Trim(strGroup) = "" Then strGroup = "Admins"

Set usr = DBEngine.Workspaces(0).Groups(strGroup).Users(strUser)
IsUserInGroup = True 'If user group "strGroup" contain user "strUser"
'if not error 3265 is called (then function return value False)


Exit_IsUserInGroup:
Exit Function

Err_IsUserInGroup:
If Err.Number <> 3265 Then '3265 >>> Item not found in this collection.
MsgBox &quot;Error No &quot; & Err.Number & vbLf & Err.Description, , &quot;Function IsUserInGroup&quot;
End If
Resume Exit_IsUserInGroup

End Function


Good luck!
Aivars

 
I'm a bit of a novice with regards to VB! I have secured my database with user level security and staff are now required to logon to access it. Where should your code that you have written be placed and what does it actually do? What I need is:

1) To be able to display the Name of the currentuser on a form by entering an expression in the control source or some other means (I have a &quot;tblUsers&quot; table whereby the UserID field is the same as the User Name for users logging into Access and the table also contains a &quot;Name&quot; field).

2) After logging in I need for either FORM1 to pop up if the person logging in is member of ADMIN or FORM2 to pop up if the person is only a USER.

3) For a combo box on a certain form to only be enabled if the currentuser is a member of Admin.

I'm very grateful for all the help you've given me! :)
 
Hi again!

I don't understand yet why don't you want to craete User and Group Account file (.MDW) for users permissions administration. It's so simply!

In addition using of DB table for Users permission accounting don't ensure the security of these data: anybody application user (even every Jack which isn't app user if DB isn't secured by password) can open your table and take all information about your app users.

Here is site's address for learning more about MS Access Workgroup Administration:


Aivars
 
Yes, I decided that it was best to secure the database with Workgroups and User Level Security, but what I need to be able to do now is:

1)After logging in I need for either FORM1 to pop up if the person logging in is member of ADMIN or FORM2 to pop up if the person is only a USER.

2)For a combo box on a certain form to only be enabled if the currentuser is a member of Admin

I am a novice with regards to VB and am unsure as to how to do this!

Thanks for the advice.
 
If IsUserInGroup Then
docmd.openform &quot;FORM1&quot;
else
docmd.openform &quot;FORM1&quot;
end if

Aivars

 
Me.cmdOpenForm.Enabled = IsUserInGroup

Does not work if I want to enable a textbox/checkbox only to admin as there is a &quot;type mismatch&quot;. Is there a way around this?

Thanks, you've been really helpful :)
 
Did you copy function's IsUserInGroup codes into any module of your DB?

Aivars
 
In addition; did you create workgroup file (.MDW)?
did you join this file?
Aivars
 
Yes, I have a workgroup file and am part of it, I have also created IsUserInGroup in a module. The format

Me.cmdOpenForm.Enabled = IsUserInGroup

may work with command buttons but did not work with my text box or combo box (type mismatch error).
 
Hey, it works now that I put the main code actually in the form's code script. If I were to put the main code into a module what should I name that module? Originally I create a module called IsUserInGroup and

Me.cmdOpenForm.Enabled = IsUserInGroup

could perhaps not find the function. How would I place the main code in module and then get it to automatically be called by Me.cmdOpenForm.Enabled = IsUserInGroup

Thanks, you solved my problem!!
 
1. If you already have any module in your DB you can copy function's IsUserInGroup codes into this module.
2. If you have not any module in your DB you may create new one and copy function's IsUserInGroup codes into this (new) module and save it.

Now you can call function IsUserInGroup from anyone procedure. Also you can use this function in the queries statemants, in the forms' controls source data definitions etc. This function will work like Access system functions (like Trim(), Left(), iif() etc.).

Aivars
 
With regards to:

If IsUserInGroup Then
docmd.openform &quot;FORM1&quot;
else
docmd.openform &quot;FORM1&quot;
end if

it states that the argument is not optional, compile error
 
Check your References. DAO must be placed to position 3 or 4 (if you have reference to stdole2.tlb - OLE Automation.

Aivars
 
What is references.DAO and how do I get access to it?
 
Open someone module (window VBA). Click <Menu bar>;<Tools>;<References>. On References dialog window find Microsoft DAO 3.6 (or 3.5) Object Library. Check it. Close References dialog window.

Aivars
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top