Hello,
I am having a problem with SQL. I tried to find a solution but after 4 days, my head is a spinning and I really don't see the solution anymore. Is there somebody here who can help me please?
I try to make an audit trail function (better is to say that I found some code on the net and try to adapt it). The code itselves without my interference works perfect, every time the user changes something in a form, the audit trail writes the old as well the new values to a table.
What I wanted to do is complete the audit trail with a function where the user has to give a reason for every change he/she does. I created an extra field in the tempaudit and audit table named "audReason" and I want to place the reason of change in this field.
There's always some kind of error but the last one I am close (I think)...(Syntax error (missing operator) in query expression is the last error I got from this code)
Thanks a lot for your assistance and patience!
Tom -
Function AuditEditBegin(sTable As String, sAudTmpTable As String, sKeyField As String, _
-
lngKeyValue As Long, bWasNewRecord As Boolean) As Boolean
-
-
On Error GoTo Err_AuditEditBegin
-
-
Dim db As DAO.Database ' Current database
-
Dim sSQL As String
-
'Dim audReason As String
-
-
'audReason = "help"
-
-
'Remove any cancelled update still in the tmp table.
-
Set db = DBEngine(0)(0)
-
sSQL = "DELETE FROM " & sAudTmpTable & ";"
-
db.Execute sSQL
-
-
' If this was not a new record, save the old values.
-
If Not bWasNewRecord Then
-
sSQL = "INSERT INTO " & sAudTmpTable & " ( audType, audDate, audUser, audReason ) " & _
-
"SELECT 'EditFrom' AS Expr1, Now() AS Expr2, NetworkUserName() AS Expr3, " ' & audReason & '" AS Expr4, " & sTable & ".* " & _
-
"FROM " & sTable & " WHERE (" & sTable & "." & sKeyField & " = " & lngKeyValue & ");"
-
'Debug.Print sSQL
-
db.Execute sSQL, dbFailOnError
-
-
End If
-
AuditEditBegin = True
-
-
Exit_AuditEditBegin:
-
Set db = Nothing
-
Exit Function
-
-
Err_AuditEditBegin:
-
Call LogError(Err.Number, Err.Description, conMod & ".AuditEditBegin()", , False)
-
Resume Exit_AuditEditBegin
-
End Function
-
1 1359
Hello,
I am having a problem with SQL. I tried to find a solution but after 4 days, my head is a spinning and I really don't see the solution anymore. Is there somebody here who can help me please?
I try to make an audit trail function (better is to say that I found some code on the net and try to adapt it). The code itselves without my interference works perfect, every time the user changes something in a form, the audit trail writes the old as well the new values to a table.
What I wanted to do is complete the audit trail with a function where the user has to give a reason for every change he/she does. I created an extra field in the tempaudit and audit table named "audReason" and I want to place the reason of change in this field.
There's always some kind of error but the last one I am close (I think)...(Syntax error (missing operator) in query expression is the last error I got from this code)
Thanks a lot for your assistance and patience!
Tom -
Function AuditEditBegin(sTable As String, sAudTmpTable As String, sKeyField As String, _
-
lngKeyValue As Long, bWasNewRecord As Boolean) As Boolean
-
-
On Error GoTo Err_AuditEditBegin
-
-
Dim db As DAO.Database ' Current database
-
Dim sSQL As String
-
'Dim audReason As String
-
-
'audReason = "help"
-
-
'Remove any cancelled update still in the tmp table.
-
Set db = DBEngine(0)(0)
-
sSQL = "DELETE FROM " & sAudTmpTable & ";"
-
db.Execute sSQL
-
-
' If this was not a new record, save the old values.
-
If Not bWasNewRecord Then
-
sSQL = "INSERT INTO " & sAudTmpTable & " ( audType, audDate, audUser, audReason ) " & _
-
"SELECT 'EditFrom' AS Expr1, Now() AS Expr2, NetworkUserName() AS Expr3, " ' & audReason & '" AS Expr4, " & sTable & ".* " & _
-
"FROM " & sTable & " WHERE (" & sTable & "." & sKeyField & " = " & lngKeyValue & ");"
-
'Debug.Print sSQL
-
db.Execute sSQL, dbFailOnError
-
-
End If
-
AuditEditBegin = True
-
-
Exit_AuditEditBegin:
-
Set db = Nothing
-
Exit Function
-
-
Err_AuditEditBegin:
-
Call LogError(Err.Number, Err.Description, conMod & ".AuditEditBegin()", , False)
-
Resume Exit_AuditEditBegin
-
End Function
-
Here is the code corrected for the syntax error.
Hopefully that fixes any issues you were having.
Without having the table and form that you're working with, kind of hard to test. -
Function AuditEditBegin(sTable As String, sAudTmpTable As String, sKeyField As String, _
-
lngKeyValue As Long, bWasNewRecord As Boolean) As Boolean
-
-
On Error GoTo Err_AuditEditBegin
-
-
Dim db As DAO.Database ' Current database
-
Dim sSQL As String
-
'Dim audReason As String
-
-
'audReason = "help"
-
-
'Remove any cancelled update still in the tmp table.
-
Set db = DBEngine(0)(0)
-
sSQL = "DELETE FROM " & sAudTmpTable & ";"
-
db.Execute sSQL
-
-
' If this was not a new record, save the old values.
-
If Not bWasNewRecord Then
-
sSQL = "INSERT INTO " & sAudTmpTable & " ( audType, audDate, audUser, audReason ) " & _
-
"SELECT 'EditFrom' AS Expr1, Now() AS Expr2, NetworkUserName() AS Expr3, '" & audReason & "' AS Expr4, " & sTable & ".* " & _
-
"FROM " & sTable & " WHERE (" & sTable & "." & sKeyField & " = " & lngKeyValue & ");"
-
Debug.Print sSQL
-
db.Execute sSQL, dbFailOnError
-
-
End If
-
AuditEditBegin = True
-
-
Exit_AuditEditBegin:
-
Set db = Nothing
-
Exit Function
-
-
Err_AuditEditBegin:
-
Call LogError(Err.Number, Err.Description, conMod & ".AuditEditBegin()", , False)
-
Resume Exit_AuditEditBegin
-
End Function
-
Hopefullt that works,
Joe P.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: newbie_mw |
last post by:
Hi, I need urgent help with a novice problem. I would appreciate any
advice, suggestions... Thanks a lot in advance! Here it is:
I created a sign-up sheet (reg.html) where people fill in their...
|
by: Kostatus |
last post by:
I have a virtual function in a base class, which is then overwritten by a
function of the same name in a publically derived class. When I call the
function using a pointer to the derived class...
|
by: Spacy |
last post by:
Am creating a HTML Report in asp.net. To save this report to excel on
client-side, i write this code:
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition",...
|
by: Kurt Watson |
last post by:
I’m having a different kind of problem with Hotmail when I sign in it
says, "Web Browser Software Limitations
Your Current Software Will Limit Your Ability to Use Hotmail
You are using a web...
|
by: Jon Davis |
last post by:
If I have a class with a virtual method, and a child class that overrides
the virtual method, and then I create an instance of the child class AS A
base class...
BaseClass bc = new ChildClass();...
|
by: Rajat Tandon |
last post by:
Hello there,
I am relatively new to the newsgroups and C#. I have never been disappointed
with the groups and always got the prompt replies to my queries.This is yet
another strange issue, I am...
|
by: Hari |
last post by:
Guys please help me to solve this strange problem what Iam
getting as follows..
Trying to instantiate a global instance of a template
class as follows :-
when i build this code with debug and...
|
by: ASP newbie |
last post by:
I cannot run my asp.net application in w2k server.
But the program works fine under w2k professional.
Can anyone tell me is there any difference in the settings?
Many thanks.
|
by: funfair |
last post by:
HI,EVERY ONE
first problem,
i have create a database in access 2003 it worked fine untill i have
format my laptop .
now im working on office 2003 on windows xp and i have norton 2006 but
im...
|
by: cty0000 |
last post by:
Please anybody help me...
I have some serious problem..
I'm doing to keep equpiment list(string)..
In my code, there are 3 page which are having 4 equpiment ID (user
control.)
like this...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| | |