Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2002
    Location
    Silver Spring, Maryland
    Posts
    74

    Unanswered: “On Error Resume Next” can no longer catch the error

    “On Error Resume Next” can no longer catch the error.

    In using Access 2000.
    I am using the following code to test and see whether I can my application can still see the tables that are linked to it. If it cannot, then it has to get linked. There is a possibility that an error will occur if sat the “Back-End” database moved. I am using the code below to catch the error. This code has been working for sometime but then all over a sudden, “On Error Resume Next” can no longer catch the error; I get the

    Run-time Error
    Invalid SQL statement: expected 'Delete', 'insert','Procedure','select' or 'update'

    Any one out there with a solution:

    Public Function CheckLinks() As Boolean
    ' Check links to the AFCIO database
    ' Returns true if links are OK.

    Dim rst As ADODB.Recordset
    Dim someString As String

    ' This is very important, other wise if you try ot open a table that
    ' does not exist, the error would end the app. But because of
    ' "On Error Resume Next", one can continue.
    ' Open backend linked table to see if connection information is correct.
    On Error Resume Next

    Set rst = New ADODB.Recordset
    rst.Open "tblCountry", CurrentProject.Connection, adOpenKeyset, adLockOptimistic

    someString = rst!CountryID

    ' If there's no error, return True.
    If Err = 0 Then
    CheckLinks = True
    Else
    CheckLinks = False
    Exit Function
    End If

    End Function

  2. #2
    Join Date
    Nov 2002
    Location
    San Francisco
    Posts
    251
    use SQL instead of name of the table.

    ...
    Set rst = New ADODB.Recordset
    rst.Open "SELECT TOP 1 FROM tblCountry", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
    ...



    I think it is generally faster to use let's say

    On Error Resume Next
    currentdb.TableDefs("myLinkedTable").Fields.Count
    If err.number .....


    jiri

  3. #3
    Join Date
    Feb 2002
    Location
    Silver Spring, Maryland
    Posts
    74
    When I try

    rst.Open "SELECT * FROM tblCountry", CurrentProject.Connection, adOpenKeyset, adLockOptimistic


    I get an error "Could not find file
    'F:\Other_Projects\OGC\DaveModified\OGC_BACKEND.md b'.

    This is not what I want. I want the app to test and see whether the linked tables can be opened and if not, trap the error and link to a backend table of choice.

    Why cant

    On Error Resume Next

    catch/unpublicise the error is beyond me. Any ideas?

  4. #4
    Join Date
    Nov 2002
    Location
    San Francisco
    Posts
    251
    why don't you try

    On Error Resume Next
    currentdb.TableDefs("myLinkedTable").Fields.Count
    If err.number <> 0 .....
    ...


    it works, although your code works too.... in my Access 97


    jiri
    Last edited by playernovis; 02-27-03 at 21:30.

Posting Permissions

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