Open a form to a specific record after log in.

bnecrush

New Member
Joined
Nov 26, 2012
Messages
31
I am trying to get a specific form to open once the user has logged on. They enter a username (from combobox) and password then go directly to their specific payrolll record. Here is the code...It doesnt seem to be working, can someone tell me where I have gone worng? Thanks!!

Private Sub cmdLogIn_Click()


'Check to see if data is entered into the Employee 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 Employeestbl to see if this matches value chosen in combo box


If Me.txtPassword.Value = DLookup("Password", "Employeetbl", "[EMPID]=" & Me.cboEmployee.Value) Then


MyEMPID = Me.cboEmployee.Value


'Close logon form and open splash screen

DoCmd.Close acForm, "Loginfrm", acSaveNo
DoCmd.OpenForm "EmployeePayrollfrm", , , "UserName'='me.cboUserName'"

Else
MsgBox "Password Invalid. Please Try Again", vbCritical + 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
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Change this
Code:
DoCmd.OpenForm "EmployeePayrollfrm", , , "UserName'='me.cboUserName'"
to this
Code:
DoCmd.OpenForm "EmployeePayrollfrm", , , "UserName=" & me.cboUserName

and when you post code, it's much easier to read if you use the CODE tags. [ CODE ]Stuff goes in here[/ CODE ] (no spaces in the CODE tags -- they are just there so they don't get interpreted...)

Denis
 
Upvote 0
Denis, Thanks! I will give that a try. Does it matter if the form has a subform with it? And I will make sure I use the CODE tags in the future, pretty new here. Thanks for the help

Tim
 
Upvote 0
Hi Tim

If you open a filtered form and it has a subform, that will open too.
I'm assuming that the combo is on a main form...

Also, if the Username is text, I gave you the wrong syntax -- that's for a number.

Use this instead.
Code:
DoCmd.OpenForm "EmployeePayrollfrm",,,"UserName='" & Me.cboUserName & "'"

Denis
 
Upvote 0

Forum statistics

Threads
1,223,264
Messages
6,171,081
Members
452,377
Latest member
bradfordsam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top