Dim stDocName As String
stDocName = "YourSecondFormNameHere"
DoCmd.OpenForm stDocName, acNormal, "", "", acAdd, acNormal
Forms![YourSecondFormNameHere]![YourForeignKeyFieldHere] = Me.[YourPrimaryKeyFromFirstFormHere]
Private Sub logincmd_Click()
'Check to see if data is entered into the UserName combo box
If IsNull(Me.Username) Or Me.Username = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.Username.SetFocus
Exit Sub
End If
'Check to see if data is entered into the password box
If IsNull(Me.Password) Or Me.Password = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.Password.SetFocus
Exit Sub
End If
'Check value of password in tblEmployees to see if this
'matches value chosen in combo box
If Me.Password.Value = DLookup("EmpPass", "Employeetbl", _
"[EmplyID]=" & Me.Username.Value) Then
EmplyID = Me.Username.Value
'Close logon form and open splash screen
DoCmd.Close acForm, "Login Form", acSaveNo
DoCmd.OpenForm "Weekly Schedule Report"
Else
MsgBox "Invalid Password. Please Try Again", vbOKOnly, _
"Invalid Entry!"
Me.Password.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 admin.", _
vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
Wow ...thank you the quick response .... However
I already have a On Click event for the button on the login form which is ...
Code:Private Sub logincmd_Click() 'Check to see if data is entered into the UserName combo box If IsNull(Me.Username) Or Me.Username = "" Then MsgBox "You must enter a User Name.", vbOKOnly, "Required Data" Me.Username.SetFocus Exit Sub End If 'Check to see if data is entered into the password box If IsNull(Me.Password) Or Me.Password = "" Then MsgBox "You must enter a Password.", vbOKOnly, "Required Data" Me.Password.SetFocus Exit Sub End If 'Check value of password in tblEmployees to see if this 'matches value chosen in combo box If Me.Password.Value = DLookup("EmpPass", "Employeetbl", _ "[EmplyID]=" & Me.Username.Value) Then EmplyID = Me.Username.Value 'Close logon form and open splash screen DoCmd.Close acForm, "Login Form", acSaveNo DoCmd.OpenForm "Weekly Schedule Report" Else MsgBox "Invalid Password. Please Try Again", vbOKOnly, _ "Invalid Entry!" Me.Password.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 admin.", _ vbCritical, "Restricted Access!" Application.Quit End If End Sub
Where would I put the code you have suggested?
Thank you in advance.
Me.[YourPrimaryKeyFromFirstFormHere]
I don't know, maybe someone else will chime in, but try it out and see, that might be a faster way to find out.
Kryst51: Do you think it will be better on the On Change event so acts as though it's synchronised? What do you think?
By the way Arvin, are both forms open at the same time?
Dim stDocName As String
stDocName = "YourSecondFormNameHere"
DoCmd.OpenForm stDocName, acNormal, "", "", acAdd, acNormal
Forms![YourSecondFormNameHere]![YourForeignKeyFieldHere] = Me.[YourPrimaryKeyFromFirstFormHere]
Forms![YourSecondFormNameHere]![YourComboBoxNameHere] = Me.[YourOtherFieldNameHere]
Also, some suggestions.
Lose the lookups at the table level, they are bad, see my signature for details.
Also, I would work on a naming convention in order to help you later while coding etc.
Also, in your employee name field, I would make that two fields, one for FirstName, one for LastName. Then in a query you can join them into one.
So when a person logs in you only want to see information for that employee on the screen that pops up?
btw, that is a combo box, just an fyi so as not to confuse (if that's what you are talking about.)
Yes![]()
Are you referring to my rant about the form displays the record ID ?![]()