Results 1 to 2 of 2

Thread: Help on automation object error

  1. #1
    Join Date
    Aug 2011
    Posts
    1

    Help on automation object error

    I try to run the following procedure from my forms vba module from a macro

    Function ZapLastRecord(strTable As String)
    Dim db As Database
    Dim rst As Recordset

    Set db = CurrentDb()
    Set rst = db.OpenRecordset(strTable)
    With rst
    If rst.RecordCount > 0 Then
    .MoveLast
    Do
    .Delete
    .MoveNext
    Loop Until .EOF
    Else
    MsgBox "There are no work orders"

    End If
    .Close

    End With

    End Function

    And I get this error:
    'You tried to run a visual basic procedure to set a property or method for an object. However, the component doesn't make the property or method available for Automation operations.

    Check the components documentation for information on the properties and methods it makes available for automation operations.

    Any ideas?

  2. #2
    Join Date
    Oct 2006
    Location
    Maitland NSW Australia
    Posts
    275
    Code:
    If rst.RecordCount > 0 Then
    .MoveLast
    Do
    .Delete
    .MoveNext
    Loop Until .EOF
    Else
    Looking at this bit of code you Move to the last record then delete the record. Then you try to move to the next record but there is no record as you are at the end of the file. Finally you want to loop until you are .EOFcode you are already there.

    I would remove the Do, MoveNext and Loop Until
    Allan

Posting Permissions

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