Results 1 to 10 of 10

Thread: SQL stmt produces Error 0

  1. #1

    Thread Starter
    Fanatic Member holly's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere on earth
    Posts
    721

    SQL stmt produces Error 0

    Hi

    I have this SQl Stmt in one of my procedure but it produces an error 0 on execute...
    Can anyone spot the obvious?

    VB Code:
    1. _strSql = " update tbl_scale_event SET " & _
    2.                " EVENT_DATETIME = '" & finalDateTime & "', " & _
    3.                " SCALE_NUMBER = '" & CInt(StrScaleNumber) & "', " & _
    4.                " EVENT_STATUS = '" & CStr(Event_Status) & "', " & _
    5.                " Operator_badge = '" & Strshift & Replace(strBadge, " '", "''") & "', " & _
    6.                " Operator_Lastname = '" & Replace(strLast_Name, "'", "''") & "' " & _
    7.                " MANUGACTURE_DATETIME = '" & (finalDateTime) & "'," & _
    8.                " WHERE " & _
    9.                " Scale_Event_ID = '" & (ObjRSprodidvalues.Fields(0).Value) & "'"
    10.                
    11.      m_Intwndprogress = 30
    12.         'if accepted display users Input/executes and initiates a scale transaction
    13.             objOcn.Execute l_strSql 'execute SQL statement

    Thanks
    Last edited by holly; Nov 20th, 2003 at 04:45 AM.
    ** HOLLY **

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    yes I can spot the obvious - error 0 means no error!

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    oooh.. just spotted the commas (and lack of) at the end of each line. here's at least part of it:
    VB Code:
    1. " Operator_Lastname = '" & Replace(strLast_Name, "'", "''") & "', " & _
    2.                " MANUGACTURE_DATETIME = '" & (finalDateTime) & "' " & _
    3.                " WHERE " & _

  4. #4

    Thread Starter
    Fanatic Member holly's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere on earth
    Posts
    721
    Si_the_geek, I have change my sql and I still receive the error
    0......the sql stmt is as follows
    VB Code:
    1. l_strSql = " update tbl_scale_event SET " & _
    2.                " EVENT_DATETIME = '" & finalDateTime & "', " & _
    3.                " SCALE_NUMBER = '" & CInt(StrScaleNumber) & "', " & _
    4.                " EVENT_STATUS = '" & CStr(Event_Status) & "', " & _
    5.                " Operator_badge = '" & Strshift & Replace(strBadge, "'", "''") & "', " & _
    6.                " Operator_Lastname = '" & Replace(strLast_Name, "'", "''") & "', " & _
    7.                " MANUFACTURE_DATETIME = '" & finalDateTime & "'" & _
    8.                " WHERE " & _
    9.                " Scale_Event_ID = '" & (ObjRSprodidvalues.Fields(0).Value) & "'"
    10.        Debug.Print l_strSql
    11.      m_Intwndprogress = 30
    12.         'if accepted display users Input/executes and initiates a scale transaction
    13.             objOcn.Execute l_strSql 'execute SQL statement

    Thanks

    If the error 0 means - no error why do I get a msgbox error...

    Thanks

    ** HOLLY **

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    Originally posted by holly

    If the error 0 means - no error why do I get a msgbox error...
    I feel a spot of deja vu...

    oh dear... I'm afraid there is only one reason: because of VERY bad code.
    The most likely problems:
    1) you are not getting an error, but are still showing the messagebox anyway
    2) you are clearing the error (using On Error.. or Err.Clear) before you show the message

    No matter what you are doing, an error code of 0 ALWAYS (and I do mean always ) means that there has been no error.

    I see nothing wrong with the SQL (but I havent looked very hard).. I'll need to know the error to help any more

  6. #6

    Thread Starter
    Fanatic Member holly's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere on earth
    Posts
    721
    Hi si_the_geek this is my full procedure

    is my code that bad?? Maybe there is something
    wrong in the code......the error I receive is 'error 0 in procedure Validate_product_code...

    Thanks for your help!!

    VB Code:
    1. Private Sub validate_product_code(ByVal strBadge As String, ByVal strLast_Name As String, ByVal mfgDate As String, ByVal Strshift As String)
    2.      'Declare Variables
    3.     Dim l_strSql As String
    4.     Dim tmpTime As Date
    5.     Dim tmpDate As Date
    6.     Dim tmpDateTime As String
    7.     Dim finalDateTime As Date
    8.     Dim StrProductLine As String
    9.     Dim ObjProdCmd As ADODB.Command
    10.     Const Event_Status = "PRODWD"
    11.     'format time and date
    12.    On Error GoTo validate_product_code_Error
    13.  
    14.       Set ObjProdCmd = New ADODB.Command 'Create new command instance
    15.         With ObjProdCmd
    16.             .ActiveConnection = objOcn 'set active connection
    17.             .CommandType = adCmdStoredProc
    18.             .CommandText = "SP_Product_ID"  'Stored Proc
    19.             .Parameters.Append .CreateParameter("@ProductID", adVarChar, adParamInput, 10, txtinformation.Text)
    20.         End With
    21.     Set ObjRSprodidvalues = ObjProdCmd.Execute  'execute SP
    22.        'executes SP to validate product
    23.          
    24.          ObjRSprodidvalues.Fields.Refresh 'refresh RS fields
    25.                
    26.      If (ObjRSprodidvalues.BOF) = True Then
    27.         DoEvents
    28.         Load frmvoidopid
    29.         frmvoidopid.Show vbModal
    30.         Exit Sub:
    31.     Else
    32.         ObjRSprodidvalues.MoveLast 'move to last RS
    33.     End If
    34.         ObjRSprodidvalues.Fields.Refresh 'refresh RS fields
    35.        lblScaleEventID = ObjRSprodidvalues.Fields(0).Value
    36.    
    37.     l_strSql = " update tbl_scale_event SET " & _
    38.                " EVENT_DATETIME = '" & finalDateTime & "', " & _
    39.                " SCALE_NUMBER = '" & CInt(StrScaleNumber) & "', " & _
    40.                " EVENT_STATUS = '" & CStr(Event_Status) & "', " & _
    41.                " Operator_badge = '" & Strshift & Replace(strBadge, "'", "''") & "', " & _
    42.                " Operator_Lastname = '" & Replace(strLast_Name, "'", "''") & "', " & _
    43.                " MANUFACTURE_DATETIME = '" & finalDateTime & "'" & _
    44.                " WHERE " & _
    45.                " Scale_Event_ID = '" & (ObjRSprodidvalues.Fields(0).Value) & "'"
    46.        Debug.Print l_strSql
    47.      m_Intwndprogress = 30
    48.         'if accepted display users Input/executes and initiates a scale transaction
    49.             objOcn.Execute l_strSql 'execute SQL statement
    50.             ObjRSprodidvalues.Fields.Refresh 'refresh the database
    51.             lblTendigitCode = "Product Code" + vbCrLf + "FW" +
    52.  
    53.      check_Product_Line (StrProductLine) 'Procedure to check the relevant product - line
    54.       m_Intwndprogress = 35
    55.    Exit Sub
    56.  
    57. validate_product_code_Error:
    58.     Call ModError_log 'All error descriptions written to a error log
    59.     MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure validate_product_code of Form frmscan"
    60.  
    61. End Sub
    Last edited by holly; Nov 20th, 2003 at 06:40 AM.
    ** HOLLY **

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    Originally posted by holly
    is my code that bad??
    only the error handling!
    the rest seems ok, apart from the indenting (which is probably fine on your pc)

    Number 1 in my last post is not the issue (your "exit sub" does the job). The trouble is the sub "ModError_log" - somewhere in here the error is reset.

    You can either show the message before you call the sub, or fix the sub.

    I'm guessing that this sub is used in several projects, so you should try to fix that. Alternatively create a new sub which showns the error and does the logging, eg:

    VB Code:
    1. Sub ShowError (SubName as String)
    2.  
    3. Dim ErrMessage as String     'Store the message
    4.    ErrMessage = "Error " & Err.Number & " (" & Err.Description & ")" & vbCr  _
    5.                        & "in procedure: " & SubName
    6.  
    7.    Call ModError_log               'Log the error
    8.  
    9.    Msgbox ErrMessage           'Show the message
    10.  
    11. End Sub
    12.  
    13.  
    14. 'in your "validate_product_code" sub:
    15. ...
    16. validate_product_code_Error:
    17.    Call ShowError ("validate_product_code of Form frmscan")
    18. ...

  8. #8

    Thread Starter
    Fanatic Member holly's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere on earth
    Posts
    721
    Si, Thanks...I will have a go at changing the ModError_Log and
    will let you know....Your help is greatly appreciated...

    Thanks
    ** HOLLY **

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    no worries.. good luck

  10. #10
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    holly

    You know, it's very simple thing to do and almost no one does it. Put a debug print immediately after you create the SQL statement. You might be amazed how quickly you can spot simple problems.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width