CPGDeveloper
Board Regular
- Joined
- Oct 8, 2008
- Messages
- 190
Hello All,
I'm using Allen Brown's Code as a Template to create an audit trail in my db (MS Access Front End, Azure SQL Server Back End). Part of it is a function that executes queries that are called in the BeforeUpdate Event of the primary data entry form. The function starts as follows:
Function AuditEditBegin(sTable As String, sAudTmpTable As String, sKeyField As String, ngKeyValue As Long, bWasNewRecord As Boolean) As Boolean
On Error GoTo Err_AuditEditBegin
Dim db As DAO.Database ' Current database
Dim sSQL As String
'Remove any cancelled update still in the tmp table.
Set db = DAO.CurrentDb
sSQL = "DELETE FROM " & sAudTmpTable & ";"
db.Execute sSQL, dbSeeChanges
...
End Function
As I mention, I call this function from the primary form's BeforeUpdate Event, as follows:
bWasNewRecord = Me.NewRecord
PUBID = Me.InvID
Call AuditEditBegin ("tblInv", "audtmpInv", "InvID", PUBID, bWasNewRecord)
The issue I'm having is the db.Execute line -- I get Error '91' -- Object or With Variable Not Set. I can, however, get the SQL Statement to Execute using DoCmd.RunSQL.
When I step through the code all the variables are properly defined, and are cleanly passed through to the function. It works fine using DoCmd.RunSQL, however my understanding is that Execute is faster, and would like to understand why it is not working in this instance. I do have 'Execute' working in very similar setups throughout my project, but here somehow it is failing. Any thoughts would be greatly appreciated. Thank You.
I'm using Allen Brown's Code as a Template to create an audit trail in my db (MS Access Front End, Azure SQL Server Back End). Part of it is a function that executes queries that are called in the BeforeUpdate Event of the primary data entry form. The function starts as follows:
Function AuditEditBegin(sTable As String, sAudTmpTable As String, sKeyField As String, ngKeyValue As Long, bWasNewRecord As Boolean) As Boolean
On Error GoTo Err_AuditEditBegin
Dim db As DAO.Database ' Current database
Dim sSQL As String
'Remove any cancelled update still in the tmp table.
Set db = DAO.CurrentDb
sSQL = "DELETE FROM " & sAudTmpTable & ";"
db.Execute sSQL, dbSeeChanges
...
End Function
As I mention, I call this function from the primary form's BeforeUpdate Event, as follows:
bWasNewRecord = Me.NewRecord
PUBID = Me.InvID
Call AuditEditBegin ("tblInv", "audtmpInv", "InvID", PUBID, bWasNewRecord)
The issue I'm having is the db.Execute line -- I get Error '91' -- Object or With Variable Not Set. I can, however, get the SQL Statement to Execute using DoCmd.RunSQL.
When I step through the code all the variables are properly defined, and are cleanly passed through to the function. It works fine using DoCmd.RunSQL, however my understanding is that Execute is faster, and would like to understand why it is not working in this instance. I do have 'Execute' working in very similar setups throughout my project, but here somehow it is failing. Any thoughts would be greatly appreciated. Thank You.