Sniper-BoOyA-
Registered User.
- Local time
- Today, 00:44
- Joined
- Jun 15, 2010
- Messages
- 204
Howdy,
Ive been trying make a Login form for our people in the lab, so if they enter data, their login initials will be automaticly entered in a txt box. Just so we can keep track of who is working on what etc.
Ive found the following code from 6 years ago that is pretty much what i had in mind.
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()
strEmpName = cboEmployee
'Na selecteren Gebr naam, focus op wachtwoord veld
Me.txtPassword.SetFocus
End Sub
Private Sub cmdLogin_Click()
'Gebruikersnaam geselecteerd?
If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
MsgBox "Selecteer uw Gebruikersnaam.", vbOKOnly, "Required Data"
Me.cboEmployee.SetFocus
Exit Sub
End If
'Wachtwoord ingevuld?
If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "Voer uw wachtwoord in.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Exit Sub
End If
'Controlleren of opgegeven wachtwoord klopt.
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then
lngMyEmpID = Me.cboEmployee.Value
'SLuit logon and start Start bij succesvol login
DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "Start"
Else
MsgBox "Wachtwoord komt niet overeen, probeer het nogmaals.", vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
End If
'Na 3 foute pogingen, sluiten db
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "Toegang Geweigerd. Neem contact op met de Administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
Private Sub Annuleren_Click()
On Error GoTo Err_Annuleren_Click
Dim stDocName As String
stDocName = "afsluitendb"
DoCmd.RunMacro stDocName
Exit_Annuleren_Click:
Exit Sub
Err_Annuleren_Click:
MsgBox Err.Description
Resume Exit_Annuleren_Click
End Sub
This code simply puts the EmpID into a string, and i added a public module so i can retrieve that information in other forms. And it works just fine.
But what i want is that it puts the EmpInitials in the string instead of the ID, so it doesnt show a number, but the actual initial (doh)
But if i either change the Dlookup into
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[strEmpInitials]=" & Me.cboEmployee.Value)
or edit the dropdown box so it takes Initials instead of ID, it stops working.
Then the Dlookup function does not work anymore.
Do you guys have any ideas ??
I wish i could upload the .mdb file but it turns out that its bigger than the limit....
Thanks in advance!
Ive been trying make a Login form for our people in the lab, so if they enter data, their login initials will be automaticly entered in a txt box. Just so we can keep track of who is working on what etc.
Ive found the following code from 6 years ago that is pretty much what i had in mind.
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()
strEmpName = cboEmployee
'Na selecteren Gebr naam, focus op wachtwoord veld
Me.txtPassword.SetFocus
End Sub
Private Sub cmdLogin_Click()
'Gebruikersnaam geselecteerd?
If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
MsgBox "Selecteer uw Gebruikersnaam.", vbOKOnly, "Required Data"
Me.cboEmployee.SetFocus
Exit Sub
End If
'Wachtwoord ingevuld?
If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "Voer uw wachtwoord in.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Exit Sub
End If
'Controlleren of opgegeven wachtwoord klopt.
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then
lngMyEmpID = Me.cboEmployee.Value
'SLuit logon and start Start bij succesvol login
DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "Start"
Else
MsgBox "Wachtwoord komt niet overeen, probeer het nogmaals.", vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
End If
'Na 3 foute pogingen, sluiten db
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "Toegang Geweigerd. Neem contact op met de Administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
Private Sub Annuleren_Click()
On Error GoTo Err_Annuleren_Click
Dim stDocName As String
stDocName = "afsluitendb"
DoCmd.RunMacro stDocName
Exit_Annuleren_Click:
Exit Sub
Err_Annuleren_Click:
MsgBox Err.Description
Resume Exit_Annuleren_Click
End Sub
This code simply puts the EmpID into a string, and i added a public module so i can retrieve that information in other forms. And it works just fine.
But what i want is that it puts the EmpInitials in the string instead of the ID, so it doesnt show a number, but the actual initial (doh)
But if i either change the Dlookup into
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[strEmpInitials]=" & Me.cboEmployee.Value)
or edit the dropdown box so it takes Initials instead of ID, it stops working.
Then the Dlookup function does not work anymore.
Do you guys have any ideas ??
I wish i could upload the .mdb file but it turns out that its bigger than the limit....
Thanks in advance!
Last edited: