Results 1 to 4 of 4
  1. #1
    Lounger
    Join Date
    Dec 2003
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    on error resume next (Acess 2000)

    How can i proceed with a procedure if an error occurs? I know of On Error Resume next, but may be i do not use it properly.
    My task is the follwowing. If there exists a field called MOL in the
    table Customers, then make another field called Employee and transfer all data into it.
    If such a field does not exist, then do not make a new field andproceed with the code further.

    My attempt runs down to the follwoing :


    On Error Resume Next
    StrSQL = "Update Customers SET MOL = Employee"
    DoCmd.RunSQL StrSQL
    On Error GoTo 0

    However, if the field MOL does not exist in the table, then i receive the
    error " enter parameter value employee"
    How can i make my function proceed if the field MOL does not exist?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: on error resume next (Acess 2000)

    I would expect a paramter prompt for MOL if MOL doesn't exist. You can use the following function to check if a field exists:

    Public Function FieldExists(TableName As String, FieldName As String) As Boolean
    Dim dbs As DAO.Database
    Dim tdf As DAO.TableDef
    Dim fld As DAO.Field
    Set dbs = CurrentDb
    Set tdf = dbs.TableDefs(TableName)
    For Each fld In tdf.Fields
    If fld.Name = FieldName Then
    FieldExists = True
    Exit For
    End If
    Next fld
    Set fld = Nothing
    Set tdf = Nothing
    Set dbs = Nothing
    End Function

    Use it as follows in your code:

    If Not FieldExists("Customers", "MOL") Then Exit Function
    If Not FieldExists("Customers", "Employee") Then Exit Function

    If you use this in a procedure instead of in a function, use Exit Sub instead of Exit Function.

  3. #3
    Lounger
    Join Date
    Dec 2003
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: on error resume next (Acess 2000)

    Thank you. This is an excellent solution indeed and i solved my rolem

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: on error resume next (Acess 2000)

    In addition to Hans' advice, you need to understand what the On Error statements do. On Error Resume Next instructs the code engine to not break or pop up an error message if an error occurs in the code. It does not prevent parameter dialogs or errors from outside the code. On Error Goto 0 disables error handling. Is that actually what you wanted to do?
    Charlotte

Posting Permissions

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