By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
463,162 Members | 742 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 463,162 IT Pros & Developers. It's quick & easy.

Run-time Error '1004'

P: 5
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.Range("A25:H44").Sort Key1:=Range("A25"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _

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.
Sep 23 '06 #1
Share this Question
Share on Google+
3 Replies

Expert 100+
P: 1,418

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


Expand|Select|Wrap|Line Numbers
  1. Set ExcelSheet = Nothing
Where ExcelSheet is the name of the created Excel object

Sep 23 '06 #2

P: 5
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.
Sep 23 '06 #3

Expert 100+
P: 1,418
I'm sure that there is a command for this...


I'm watching...

Expand|Select|Wrap|Line Numbers
  2. ExcelSheet.SaveAs "C:\TEST.XLS"
Sep 23 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.