Run-time Error '1004'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Maverick
    New Member
    • Sep 2006
    • 5

    #1

    Run-time Error '1004'

    I'm new to this, but I have received so much great information here, I had to join. Here is a problem am encountering with the following code in MS Access:


    objSht.Activate
    objSht.Range("A 25:H44").Select
    objSht.Range("A 25:H44").Sort Key1:=Range("A2 5"), Order1:=xlAscen ding, Header:=xlGuess , _
    OrderCustom:=1, MatchCase:=Fals e, Orientation:=xl TopToBottom, _
    DataOption1:=xl SortTextAsNumbe rs

    Everything works fine up to this point and the strange thing is the above code also works the first time I run it, but for subsequent runs I get

    "Run-time Error '1004'"
    "Method 'Range' of object '_Global' failed"

    Do I need to reset something at the end of my code?

    Thanks for the help.
  • PEB
    Recognized Expert Top Contributor
    • Aug 2006
    • 1418

    #2
    Hi,

    Usually when you invokes Excel from Access u create an object... When u finish using this object you need to set it to nothing

    like:

    Code:
    Set ExcelSheet = Nothing
    Where ExcelSheet is the name of the created Excel object

    :)

    Comment

    • Maverick
      New Member
      • Sep 2006
      • 5

      #3
      Thank you. Works beautifully. Would it be possible to now do a "Save As" to the file I just created and pass the new filename with a variable? Thank you so much for your help.

      Comment

      • PEB
        Recognized Expert Top Contributor
        • Aug 2006
        • 1418

        #4
        I'm sure that there is a command for this...

        Wait...

        I'm watching...

        Code:
        ExcelSheet.SaveAs "C:\TEST.XLS"
        :)

        Comment

        Working...