By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,795 Members | 1,216 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,795 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.Activate
objSht.Range("A25:H44").Select
objSht.Range("A25:H44").Sort Key1:=Range("A25"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers

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


PEB
Expert 100+
P: 1,418
PEB
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:

Expand|Select|Wrap|Line Numbers
  1. Set ExcelSheet = Nothing
  2.  
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

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

Wait...

I'm watching...

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

Post your reply

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