D
Don Barton
I am trying to update a table using VBA and SQL. A form is filled out
with user ID and PW, then these data are sent to global variables.
The global variables are used to create a record in tblUserActivity.
except when I get to the recordset.update. When execution occurs at
this point, my error routine fires. Is this a primary key field
issue? I have a primary key autonumber field defined for this
table.
------------------------------------------
Public Function WriteAuditTrail()
On Error GoTo Err_WATError
Dim strSQL As String
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb()
strSQL = "SELECT * FROM tblUserActivity;"
Debug.Print strSQL
Set rst = db.OpenRecordset(strSQL)
With rst
.AddNew
!PWUserName = gActiveUser
!PWDateTime = Now
!pwActivity = gUserActivity
!pwSecStatus = gSecStatus
.Update
End With
rst.Close
Exit_WriteAuditTrail:
Exit Function
Err_WATError:
MsgBox "There has been a error in recording UserInfo"
Resume Exit_WriteAuditTrail
Set rst = Nothing
Set db = Nothing
End Function
with user ID and PW, then these data are sent to global variables.
The global variables are used to create a record in tblUserActivity.
forward. Regarding the code below, everythings seems to be workingFrom what I've read of previous posts, this should be pretty straight
except when I get to the recordset.update. When execution occurs at
this point, my error routine fires. Is this a primary key field
issue? I have a primary key autonumber field defined for this
table.
------------------------------------------
Public Function WriteAuditTrail()
On Error GoTo Err_WATError
Dim strSQL As String
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb()
strSQL = "SELECT * FROM tblUserActivity;"
Debug.Print strSQL
Set rst = db.OpenRecordset(strSQL)
With rst
.AddNew
!PWUserName = gActiveUser
!PWDateTime = Now
!pwActivity = gUserActivity
!pwSecStatus = gSecStatus
.Update
End With
rst.Close
Exit_WriteAuditTrail:
Exit Function
Err_WATError:
MsgBox "There has been a error in recording UserInfo"
Resume Exit_WriteAuditTrail
Set rst = Nothing
Set db = Nothing
End Function