Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2003
    Location
    HongKonger@NewYork
    Posts
    9

    Question Unanswered: VBA code for tracking user logiin records

    I have written the following codes to track the fields and the values having been changed

    Private Sub Form_Current()
    Dim db As Database, dbName As String
    Dim rst As Recordset
    Dim ctlC As Control
    Set db = CurrentDb
    Set rst = db.OpenRecordset("GeneralContactInfo_log")
    Dim x
    x = Forms!GeneralContactInfoForm!contactID '(or the record id from the form)
    For Each ctlC In Me.Controls
    If TypeOf ctlC Is TextBox Then
    If ctlC.Value <> ctlC.OldValue Or IsNull(ctlC.OldValue) Then
    If Not IsNull(ctlC.Value) Then

    rst.AddNew
    rst!Luser = CurrentUser()
    rst!Ltime = Now()
    rst!Ldatabase = db.Name
    rst!Lfield = ctlC.Name
    rst!LfieldOldValue = ctlC.OldValue
    rst!LfieldNewValue = ctlC.Value
    rst!Laction = "Saved/accessd/modified"
    rst!Lrecordnum = x
    rst.update
    End If
    End If
    End If
    Next ctlC
    rst.Close
    Set rst = Nothing
    End Sub

    but it doesn't track any records in GeneralContactInformation_log,
    what's wrong??

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    dunno
    ...but do you get what you expect with:

    If TypeOf ctlC Is TextBox Then
    msgbox "ctlC was a text box"
    If ctlC.Value <> ctlC.OldValue Or IsNull(ctlC.OldValue) Then
    msgbox "ctlC.Value <> ctlC.OldValue Or IsNull(ctlC.OldValue)"
    If Not IsNull(ctlC.Value) Then
    msgbox "Not IsNull(ctlC.Value) was true"

    there is no other obvious source of error.

    (but must you dim X as variant?: dim x as long seems sweeter)

    izy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •