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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HOW CAN I RECORD DATE AND USERS NAME AUTO!!!!

Status
Not open for further replies.

chubby

Programmer
Apr 28, 2001
278
0
0
US
I was wondering how can I have the date and the Endusers name automatically placed into a table each time the EndUser opens or closes a form? I tried using a Macro and Append query but it does seem to work...

Chubby
 
Are you trying to write history to a table regarding who is opening and closing forms and when? Assuming this is the table to store the desired information:

tblFormHistory
-------------
FormHistoryID
EndUserID
FormName
DateOpened
DateClosed


Create these functions in a module:

Public Function FormOpenHistory(strFormName As String) As Integer

Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("tblFormHistory")

rst.AddNew
rst.Fields("EndUserID") = DLookup("UserID", "tblCurrentUser")
rst.Fields("FormName") = strFormName
rst.Fields("DateOpened") = Now()
FormOpenHistory = rst.Fields("FormHistoryID")
rst.Update
rst.Close

End Function

Public Function FormCloseHistory(intFormID As Integer)
Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("tblFormHistory")

rst.Index = "PrimaryKey"
rst.Seek "=", intFormID
rst.Edit
rst.Fields("DateClosed") = Now()
rst.Update
rst.Close

End Function


For each form that you want history from use these for the Open and Close events:

Private Sub Form_Close()
FormCloseHistory intFormHistoryID
End Sub

Private Sub Form_Open(Cancel As Integer)
intFormHistoryID = FormOpenHistory(Me.Name)
End Sub

This assumes a Global variable:
Dim intFormHistoryID As Integer

The DLookUp statement assumes you have the EndUser information entered in a table - you may need to modify to your needs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top