PDA

View Full Version : Passing User from Login form to Main form



Waubain
11-13-2010, 09:33 AM
I am trying to pass the Access Code from the Login from to the Main form in a variable called User. The plan is when the user adds a new record in the Main form the User value is added to a control source in Main table field named strUser. Here is the part of the code. Thank you.

'frmLogIn Form Code

'Check value of password in tblUser to see if matches

If Me.txtVerifyCode.Value = DLookup("VerifyCode", "tblUsers", "AccessCode='" & Me.txtAccessCode.Value & "'") Then

lngMyEmpID = Me.txtAccessCode.Value

'Close logon form and open main form screen, carries User to Main form

DoCmd.Close acForm, "frmLogin", acSaveNo
DoCmd.OpenForm "frmMain", acNormal, , , , acWindowNormal, "txtAccessCode.Value"


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



'frmMain Code

Private Sub Form_Open(Cancel As Integer)
Dim User As String
User = CString(Me.OpenArgs)
Refresh
End Sub

OBP
11-13-2010, 12:27 PM
You may find that User is a reserved word, you could try txtUser instead.
Or you could set txtAccessCode as a Public Variable which is automatically available to any form.