Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COPY FIELD VALUE FROM FORM TO ANOTHER FIELD ON A TABLE 1

Status
Not open for further replies.

duhu

Technical User
Feb 3, 2009
5
GB
Hi guys, i have a login form "frm_logon" whose source is a table "tblemployees" with the fields:
*Emp_ID
*Emp_Name
*Emp_password.

I also have another table called "tbl_loginLOG" which has the fields:

*User (which is a lookup from Emp_Name field in tblEmployees),
*Login_Date
*Login_Time

I would like to know how i can capture the value in the username field and copy this to the User field in tbl_loginLOG. I would like this to happen when the user has clicked the "OK" button on the "frm_logon" after successfully typing in the correct username and password.
I want to be able to use the information to keep a record of who has entered information into another form called frm_history.
I HAVE COPIED THE CODE FROM THE On_Click event of the "OK" BUTTON on frm_Logon, SEE BELOW.
-------------------------------------------------

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, "frm_Logon", acSaveNo
DoCmd.Close acForm, "frm_inventory"
DoCmd.Close acForm, "frm_Options"
DoCmd.OpenForm "frm_Manager"

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 LapStock system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If

End Sub
 
First, why TWO fields for storing a SINGLE DateTime value in tbl_loginLOG ?

In your Click event procedure:
...
CurrentDb.Execute "INSERT INTO tbl_loginLOG ([User],Login_DateTime) VALUES (" & lngMyEmpID & ",Now())"
DoCmd.Close acForm, "frm_Logon", acSaveNo
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
As per your comment i've incorporated the Date & Time fields into just one field.
Would you be able to tell me how I can have the username in the tbl_loginLOG also entered into a field called "UserEnt" in a form called "frm_history".
This form is used to record the movement of laptops in and out of a cupboard and i would like the name of users who input entries in the history table also shown. At the moment the form has the "Information, Date & Time" fields displayed. I would like to have the username of the most recent logged on user to populate the "UserEnt" field in this form/table.

SEE:
(shows the query from which frm_History is derived, to enter new information)

(shows The history form, click on "Add Note" which opens up frm_History to make a new entry)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top