Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

time stamp login

BigPete85BigPete85 Member Posts: 30
[b][red]This message was edited by BigPete85 at 2007-1-4 12:11:19[/red][/b][hr]
I created a simple log in screen, nothing too facny with this code

Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset

If IsNull(Me.txtlogin) Then
MsgBox "Please enter a valid user name.", vbExclamation, "Error"
Me.txtlogin.SetFocus
Exit Sub


ElseIf IsNull(Me.txtpassword) Then
MsgBox "Please enter a valid password.", vbExclamation, "Error"
Me.txtpassword.SetFocus
Exit Sub
End If


rs.Open "SELECT * FROM logininformation WHERE(login = """ & txtlogin.Value & """ AND password = """ & txtpassword.Value & """)", _
CurrentProject.Connection, adOpenKeyset, adLockOptimistic


If rs.EOF Then
MsgBox "Invalid user name or password. Please try again.", vbExclamation, "Error"
Me.txtlogin.SetFocus
Exit Sub
End If


MsgBox "Login Successful.", vbInformation, "Confirm!"
DoCmd.Close
Exit Sub



What i would like to do is put a time stamp in the record for each time the log in was sucessful.

The fields in the Login Table are : Login, password, Date

So whenever there is a successful login, the date field in the table will update to time of the login. I know the code is =Now() to get the exact time of the current date. But how do i update the table with the current date for that record when the login is successful?


Comments

  • dokken2dokken2 Member Posts: 532
    : [b][red]This message was edited by BigPete85 at 2007-1-4 12:11:19[/red][/b][hr]
    : I created a simple log in screen, nothing too facny with this code
    :
    : Dim rs As ADODB.Recordset
    : Set rs = New ADODB.Recordset
    :
    : If IsNull(Me.txtlogin) Then
    : MsgBox "Please enter a valid user name.", vbExclamation, "Error"
    : Me.txtlogin.SetFocus
    : Exit Sub
    :
    :
    : ElseIf IsNull(Me.txtpassword) Then
    : MsgBox "Please enter a valid password.", vbExclamation, "Error"
    : Me.txtpassword.SetFocus
    : Exit Sub
    : End If
    :
    :
    : rs.Open "SELECT * FROM logininformation WHERE(login = """ & txtlogin.Value & """ AND password = """ & txtpassword.Value & """)", _
    : CurrentProject.Connection, adOpenKeyset, adLockOptimistic
    :
    :
    : If rs.EOF Then
    : MsgBox "Invalid user name or password. Please try again.", vbExclamation, "Error"
    : Me.txtlogin.SetFocus
    : Exit Sub
    : End If
    :
    :
    : MsgBox "Login Successful.", vbInformation, "Confirm!"
    : DoCmd.Close
    : Exit Sub
    :
    :
    :
    : What i would like to do is put a time stamp in the record for each time the log in was sucessful.
    :
    : The fields in the Login Table are : Login, password, Date
    :
    : So whenever there is a successful login, the date field in the table will update to time of the login. I know the code is =Now() to get the exact time of the current date. But how do i update the table with the current date for that record when the login is successful?
    :
    :
    :

    This works using Sql and Access commands-

    [/code]
    'TRACK USERS THAT LOG ON/OFF THE DATABASE
    Public Sub Audit(myAction As String)
    Dim CurrUser As String, myDate As String, myTime As String

    On Error Resume Next

    'CURRENT USER FROM ENVIRONMENT VARIABLE
    CurrUser = Environ("username")
    'PUT QUOTES AROUND STRING VALUES
    CurrUser = "'" & CurrUser & "'"
    myAction = "'" & myAction & "'"
    'PUT # AROUND DATE VALUE
    myDate = "#" & Date & "#"
    myTime = "'" & Time & "'"

    'SQL INSERT
    sql = "INSERT INTO Audit ( [user], [action], [date], [time] ) " & _
    "SELECT " & CurrUser & " AS expr1, " & _
    myAction & " AS expr2, " & _
    myDate & " AS expr3, " & _
    myTime & " AS expr4;"

    DoCmd.SetWarnings False
    'RUN SQL INSERT
    DoCmd.RunSQL sql
    DoCmd.SetWarnings True
    End Sub
    [/code]
Sign In or Register to comment.