473,395 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

SQL problem, please help?

9
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


Expand|Select|Wrap|Line Numbers
  1. Function AuditEditBegin(sTable As String, sAudTmpTable As String, sKeyField As String, _
  2.     lngKeyValue As Long, bWasNewRecord As Boolean) As Boolean
  3.  
  4. On Error GoTo Err_AuditEditBegin
  5.  
  6.     Dim db As DAO.Database           ' Current database
  7.     Dim sSQL As String
  8.     'Dim audReason As String
  9.  
  10.     'audReason = "help"
  11.  
  12.     'Remove any cancelled update still in the tmp table.
  13.     Set db = DBEngine(0)(0)
  14.     sSQL = "DELETE FROM " & sAudTmpTable & ";"
  15.     db.Execute sSQL
  16.  
  17.     ' If this was not a new record, save the old values.
  18.     If Not bWasNewRecord Then
  19.         sSQL = "INSERT INTO " & sAudTmpTable & " ( audType, audDate, audUser, audReason ) " & _
  20.             "SELECT 'EditFrom' AS Expr1, Now() AS Expr2, NetworkUserName() AS Expr3, " ' & audReason & '" AS Expr4, " & sTable & ".* " & _
  21.             "FROM " & sTable & " WHERE (" & sTable & "." & sKeyField & " = " & lngKeyValue & ");"
  22.             'Debug.Print sSQL
  23.         db.Execute sSQL, dbFailOnError
  24.  
  25.     End If
  26.     AuditEditBegin = True
  27.  
  28. Exit_AuditEditBegin:
  29.     Set db = Nothing
  30.     Exit Function
  31.  
  32. Err_AuditEditBegin:
  33.     Call LogError(Err.Number, Err.Description, conMod & ".AuditEditBegin()", , False)
  34.     Resume Exit_AuditEditBegin
  35. End Function
  36.  
Mar 27 '08 #1
1 1359
PianoMan64
374 Expert 256MB
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


Expand|Select|Wrap|Line Numbers
  1. Function AuditEditBegin(sTable As String, sAudTmpTable As String, sKeyField As String, _
  2.     lngKeyValue As Long, bWasNewRecord As Boolean) As Boolean
  3.  
  4. On Error GoTo Err_AuditEditBegin
  5.  
  6.     Dim db As DAO.Database           ' Current database
  7.     Dim sSQL As String
  8.     'Dim audReason As String
  9.  
  10.     'audReason = "help"
  11.  
  12.     'Remove any cancelled update still in the tmp table.
  13.     Set db = DBEngine(0)(0)
  14.     sSQL = "DELETE FROM " & sAudTmpTable & ";"
  15.     db.Execute sSQL
  16.  
  17.     ' If this was not a new record, save the old values.
  18.     If Not bWasNewRecord Then
  19.         sSQL = "INSERT INTO " & sAudTmpTable & " ( audType, audDate, audUser, audReason ) " & _
  20.             "SELECT 'EditFrom' AS Expr1, Now() AS Expr2, NetworkUserName() AS Expr3, " ' & audReason & '" AS Expr4, " & sTable & ".* " & _
  21.             "FROM " & sTable & " WHERE (" & sTable & "." & sKeyField & " = " & lngKeyValue & ");"
  22.             'Debug.Print sSQL
  23.         db.Execute sSQL, dbFailOnError
  24.  
  25.     End If
  26.     AuditEditBegin = True
  27.  
  28. Exit_AuditEditBegin:
  29.     Set db = Nothing
  30.     Exit Function
  31.  
  32. Err_AuditEditBegin:
  33.     Call LogError(Err.Number, Err.Description, conMod & ".AuditEditBegin()", , False)
  34.     Resume Exit_AuditEditBegin
  35. End Function
  36.  
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.

Expand|Select|Wrap|Line Numbers
  1. Function AuditEditBegin(sTable As String, sAudTmpTable As String, sKeyField As String, _
  2.     lngKeyValue As Long, bWasNewRecord As Boolean) As Boolean
  3.  
  4. On Error GoTo Err_AuditEditBegin
  5.  
  6.     Dim db As DAO.Database           ' Current database
  7.     Dim sSQL As String
  8.     'Dim audReason As String
  9.  
  10.     'audReason = "help"
  11.  
  12.     'Remove any cancelled update still in the tmp table.
  13.     Set db = DBEngine(0)(0)
  14.     sSQL = "DELETE FROM " & sAudTmpTable & ";"
  15.     db.Execute sSQL
  16.  
  17.     ' If this was not a new record, save the old values.
  18.     If Not bWasNewRecord Then
  19.         sSQL = "INSERT INTO " & sAudTmpTable & " ( audType, audDate, audUser, audReason ) " & _
  20.             "SELECT 'EditFrom' AS Expr1, Now() AS Expr2, NetworkUserName() AS Expr3, '" & audReason & "' AS Expr4, " & sTable & ".* " & _
  21.             "FROM " & sTable & " WHERE (" & sTable & "." & sKeyField & " = " & lngKeyValue & ");"
  22.             Debug.Print sSQL
  23.         db.Execute sSQL, dbFailOnError
  24.  
  25.     End If
  26.     AuditEditBegin = True
  27.  
  28. Exit_AuditEditBegin:
  29.     Set db = Nothing
  30.     Exit Function
  31.  
  32. Err_AuditEditBegin:
  33.     Call LogError(Err.Number, Err.Description, conMod & ".AuditEditBegin()", , False)
  34.     Resume Exit_AuditEditBegin
  35. End Function
  36.  
Hopefullt that works,

Joe P.
Mar 29 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
11
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...
3
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",...
0
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...
28
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();...
9
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...
5
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...
11
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.
1
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...
2
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...
0
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...
0
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...
0
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
1
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...
0
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...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.