Results 1 to 5 of 5

Thread: Error Line: 0 / Error: (0)...What is my error??

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    2

    Exclamation Error Line: 0 / Error: (0)...What is my error??

    Hi guys

    I am using VBA to insert some data into a table should the appropriate record exist on a different table.
    I am opening and closing a Recordset to retrieve record values which loops until it gets to the end of the file.
    It goes through the entire loop fine, creates files etc., however, it seems to catch an error at the end and no matter what I try I can't seem to figure out what is causing it!
    I have included the basics of the code...any help on this would be very much appreciated.
    Thanks a lot

    Kate

    VB Code:
    1. sTableName = "SELECT * FROM tblRestaurants"
    2.  
    3.  rs.Open sTableName, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
    4.  rs.MoveFirst
    5.  
    6.  ' Loop to check firstly if the record exists
    7.  ' If it does exist create the appropriate files
    8.  
    9. While Not rs.EOF
    10.  
    11.     counter = counter + 1
    12.     strSQL = sTableName & " WHERE Number=" & counter
    13.     rs2.Open strSQL, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
    14.  
    15.         If rs2.EOF() <> True Then
    16.             recordCount = recordCount + 1
    17.         End If
    18.  
    19.         rs2.Close
    20.         Set rs2 = Nothing
    21.                  
    22.         If recordCount <= 0 Then
    23.    
    24.                 rs.MovePrevious
    25.                
    26.         Else
    27.                 strNewFileName = DLookup("[NewFileName]", "tblRestaurants", "[Number] = " & counter)
    28.                
    29.                     DoCmd.RunSQL "DELETE tmpAPFiles.* FROM tmpAPFiles;"
    30.                     strSQL = "INSERT INTO tmpAPFiles ( UnitID, DocumentDate, RefNum, DocumentNumber, SupplierName, TotalAmount, Field7, GLCode, GLAmount, GLName, PaymentType, ManChequeNum, SupplierAccountNumber, SupplierID, PaymentType2, LastDayOfPWY )SELECT tblAPFiles.UnitID, tblAPFiles.DocumentDate, tblAPFiles.RefNum, tblAPFiles.DocumentNumber, tblAPFiles.SupplierName, tblAPFiles.TotalAmount, tblAPFiles.Field7, tblAPFiles.GLCode, tblAPFiles.GLAmount, tblAPFiles.GLName, tblAPFiles.PaymentType, tblAPFiles.ManChequeNum, tblAPFiles.SupplierAccountNumber, tblAPFiles.SupplierID, tblAPFiles.PaymentType2, tblAPFiles.LastDayOfPWY FROM tblRestaurants INNER JOIN tblAPFiles ON tblRestaurants.RestNum = tblAPFiles.UnitID WHERE (((tblRestaurants.Number)=" & counter & "));"
    31.                     DoCmd.RunSQL strSQL
    32.                     DoCmd.TransferText acExportDelim, , "qrytmpAPFiles", "w:\unitdata\polling\ap\fixed\" & strNewFileName, False
    33.                     recordCount = 0
    34.                    
    35.                 End If                              
    36.         End If
    37.    
    38.  rs.MoveNext
    39.    
    40. Wend
    41.  
    42.  ' Check if the recordset has anything in it
    43.  If (rs Is Nothing) Then
    44.     If rs.State <> 0 Then
    45.         rs.Close
    46.         Set rs = Nothing
    47.     End If
    48. End If
    49.  
    50.  On Error GoTo PROC_ERR    
    51.    
    52. PROC_ERR:
    53.       MsgBox "Error Line: " & Erl & vbCrLf & vbCrLf & "Error: (" & Err.Number & ") " & Err.Description, vbCritical
    54.     Exit Function
    Attached Images Attached Images  

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Error Line: 0 / Error: (0)...What is my error??

    Your On Error GoTo should be the first line in the procedure. It should always be the first line in the procedure.

    I suspect it is returning the 0's and, no error description, because the error trap isn't catching the error soon enough to tell you what is going on.

    Also, there may, in fact, be no error at all. Your code will ALWAYS hit the error trap because you have no exit in your procedure.

    Immedately before the line: PROC_ERR

    there should be an Exit Sub. This way, if there is no error it will exit before it hits your error coding.

  3. #3
    Hyperactive Member eranfox's Avatar
    Join Date
    May 2001
    Posts
    492

    Re: Error Line: 0 / Error: (0)...What is my error??

    Hello ksalholm,
    Did you try to debug?

    try to run your code step by step and you will find the line of code that is wrong.

    Best Regards,
    ERAN
    Eran Fox
    ASSEMBLER,C,C++,VB6,SQL...

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Error Line: 0 / Error: (0)...What is my error??

    Hack's got it right, and a few more things:

    1) the On Error Goto needs to be the first line in the sub
    2) There is no error. Your lack of Exit Sub before the error handler causes the code in the error handler to run
    3) You will always get 0 for the Erl even when there is an error. That's because you have no line numbers in the sub.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    2

    Resolved Re: Error Line: 0 / Error: (0)...What is my error??

    Aaah, I see. I didn't realise that the code executes even if no error is thrown. Thought it was like a basic try-catch statement.
    Excellent to know.
    Thanks a lot guys, you've been very informative.
    Kate

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