A
Access97VBstumpted
I am develooping an audit trail script in VB for an Access 97 application. Is
there a visual basic 6.0 script that can determine if a table field is a
primary key? I wish to capture the unique primary key for each record that
is viewed/updated/created. Here is a snippet of how my code is structured,
it only updates a log table when a new record is created.
Function AuditTrail()
On Error GoTo Err_Handler
Dim dbs As DAO.DATABASE
Dim rs As DAO.Recordset
Dim MyForm As Form, C As Control, xName As String
Set MyForm = Screen.ActiveForm
Set dbs = CurrentDb
Set rs = dbs.OpenRecordset("AddressBookLog", dbOpenDynaset)
'If new record, record it in audit trail and exit sub.
If MyForm.NewRecord = True Then
With rs
.AddNew
![NetworkUserID] = NetworkUser()
![ComputerName] = ComputerName()
![UserSecurityID] = User.SecurityID
![ApplicationUserID] = User.UserID
![Application] = dbs.Name
![FormName] = MyForm.Name
'![UniquePrimaryRecordKey] = ?
![RecordID] = MyForm.CurrentRecord
![DataBefore] = "New Record Created"
.UPDATE
End With
End If
TryNextC:
Exit Function
Err_Handler:
If Err.NUMBER <> 64535 Then
MsgBox "Error #: " & Err.NUMBER & vbCrLf & "Description: " &
Err.Description
End If
Resume TryNextC
End Function
there a visual basic 6.0 script that can determine if a table field is a
primary key? I wish to capture the unique primary key for each record that
is viewed/updated/created. Here is a snippet of how my code is structured,
it only updates a log table when a new record is created.
Function AuditTrail()
On Error GoTo Err_Handler
Dim dbs As DAO.DATABASE
Dim rs As DAO.Recordset
Dim MyForm As Form, C As Control, xName As String
Set MyForm = Screen.ActiveForm
Set dbs = CurrentDb
Set rs = dbs.OpenRecordset("AddressBookLog", dbOpenDynaset)
'If new record, record it in audit trail and exit sub.
If MyForm.NewRecord = True Then
With rs
.AddNew
![NetworkUserID] = NetworkUser()
![ComputerName] = ComputerName()
![UserSecurityID] = User.SecurityID
![ApplicationUserID] = User.UserID
![Application] = dbs.Name
![FormName] = MyForm.Name
'![UniquePrimaryRecordKey] = ?
![RecordID] = MyForm.CurrentRecord
![DataBefore] = "New Record Created"
.UPDATE
End With
End If
TryNextC:
Exit Function
Err_Handler:
If Err.NUMBER <> 64535 Then
MsgBox "Error #: " & Err.NUMBER & vbCrLf & "Description: " &
Err.Description
End If
Resume TryNextC
End Function