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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to give different access form to normal user and admin user? 1

Status
Not open for further replies.

awinnn

MIS
Jul 21, 2003
166
MY
Hi,
I have a UserId, Pwd and Dept. in the login form. After user has successfully login, user will directly go to FrmMain. While Admin user should be directly go to the other form, FrmMenu. My problem is with the Admin user. Any idea?

this is my code,
------------------------------------------------
Public UserType As Integer

Private Sub CmdOK_Click()
On Error GoTo Err_CmdOK_Click

Dim dbs As DAO.Database
Dim rst As DAO.Recordset

If IsNull([UserId]) Or IsNull([Pwd]) Then
MsgBox "You must enter both user id and password."
DoCmd.GoToControl "UserId"
Else
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("Select tblUserLogin.*
FROM tblUserLogin WHERE
(tblUserLogin.User_Id='" & (Forms!
[FrmLogin]![UserId]) & "') ")
If (StrComp(Forms![FrmLogin]![Pwd], rst
(&quot;Password&quot;), 1) <> 0) Then
MsgBox &quot;Wrong Password. Please re-enter !!&quot;
DoCmd.GoToControl &quot;Pwd&quot;
Else
Me.Visible = False
DoCmd.OpenForm &quot;FrmMain&quot;
End If
End If

Exit_CmdOK_Click:
Exit Sub

Err_CmdOK_Click:
MsgBox Err.Description
Resume Exit_CmdOK_Click

End Sub
------------------------------------------------
thanx in advance..:)
 
Hi awinnn,

First of all, as far as I can see from your code, if a user types in a non-existing username, you'll get an EOF when you call rst(&quot;Password&quot;).

A better scheme might be to say:

If rst.EOF Then
MsgBox &quot;Unknown User Id.&quot;
DoCmd.GoToControl &quot;UserId&quot;
Exit Sub
End If

If (StrComp(Forms![FrmLogin]![Pwd],
rst (&quot;Password&quot;), 1) <> 0) Then
MsgBox &quot;Wrong Password. Please re-enter !!&quot;
DoCmd.GoToControl &quot;Pwd&quot;
End If


Secondly, if you want a certain user id, say &quot;Admin&quot; to go to a different form, just use:

If (StrComp(Forms![FrmLogin]![Pwd], rst
(&quot;Password&quot;), 1) <> 0) Then
MsgBox &quot;Wrong Password. Please re-enter !!&quot;
DoCmd.GoToControl &quot;Pwd&quot;
Else
Me.Visible = False
If LCase(Forms![FrmLogin]![UserId]) = &quot;admin&quot; Then
DoCmd.OpenForm &quot;FrmMenu&quot;
Else
DoCmd.OpenForm &quot;FrmMain&quot;
End If
End If



Dave Mc Donald
 
Hi Dave,
thanx for your help..it works..:)
thanx again!

 
Would love to see the database that is working.

Phil phil@drcdoc.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top