username and password form

G

Guest

Hi,
I used the attached code which is for open Username and password form.(taken
from: http://www.databasedev.co.uk/login.html) but there is one more
something i would like to do it. I want to add a filed in tblEmployees table
which is called Struserforms which uses to filled up with form name.
Moreover, the employee can see the form which is specified for him once he
login .
For example:
User: shaham0v can see form1
User: shaham1v can see form 2
And so on
The tblEmployees contains:
lngEmpID, strEmpName, stremppassword , straccess,
and the code is
Option Compare Database
Private intLogonAttempts As Integer

Private Sub Form_Open(Cancel As Integer)
'On open set focus to combo box
Me.cboEmployee.SetFocus
End Sub

Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
Me.txtPassword.SetFocus
End Sub

Private Sub cmdLogin_Click()

'Check to see if data is entered into the UserName combo box

If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cboEmployee.SetFocus
Exit Sub
End If

'Check to see if data is entered into the password box

If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Exit Sub
End If

'Check value of password in tblEmployees to see if this matches value chosen
in combo box

If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees",
"[lngEmpID]=" & Me.cboEmployee.Value) Then

lngMyEmpID = Me.cboEmployee.Value

'Close logon form and open splash screen

DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "frmSplash_Screen"

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid
Entry!"
Me.txtPassword.SetFocus
End If

'If User Enters incorrect password 3 times database will shutdown

intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact
your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If

End Sub
 
S

Scott McDaniel

Hi,
I used the attached code which is for open Username and password form.(taken
from: http://www.databasedev.co.uk/login.html) but there is one more
something i would like to do it. I want to add a filed in tblEmployees table
which is called Struserforms which uses to filled up with form name.
Moreover, the employee can see the form which is specified for him once he
login .

You can get the value from your table in several ways, I'll show you how to do it with ADO recordsets:

Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset

rst.Open "SELECT strUserForm FROM tblEmployees WHERE lngEmpID=" & Me.cboEmployee, CurrentProject.Connection

If not (rst.EOF and rst.BOF) then
'found a record
If Len(rst("strUserForm"))>0 Then
DoCmd.OpenForm rst("strUserForm")
End If
End If

set rst = Nothing

You'd do this AFTER you authenticate your user ...


Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 
G

Guest

Thank you Scott very very mach.
Can you tell me please where should I put the code, in which part of my code?
Your help is highly appreciated

Thanks!
 
S

Scott McDaniel

Thank you Scott very very mach.
Can you tell me please where should I put the code, in which part of my code?
Your help is highly appreciated

In the cmdLogin procedure, in this area:

If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees",
"[lngEmpID]=" & Me.cboEmployee.Value) Then

lngMyEmpID = Me.cboEmployee.Value

'Close logon form and open splash screen


<<<<<<<<<<<<<<<<<assume that we have a vlaid employee, so the code would go here>>>>>>>>>>>>>>


DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "frmSplash_Screen"

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid
Entry!"
Me.txtPassword.SetFocus
End If

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

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

Similar Threads


Top