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

Run-Time Error 1004

P: n/a
I have a bit of code tied to a command button in Access that runs a
query then transfers it to a new Excel worksheet (& new file). It
works fine EVERY OTHER
TIME THAT I RUN IT....what the 'heck is going on? I get the following
error message on the odd runs:

Run-Time Error 1004

Method 'Columns' of object '_Global' failed
.....the query results make it to the worksheet. The error occurs in my
section
of code that formats the worksheet once the data has been imported. I
have copied the applicable section of data below:

THIS IS WHERE I GET THE ERROR (EVERY OTHER TIME THAT I RUN IT)
Columns("A:A").EntireColumn.AutoFit
Rows("1:6").Select
Selection.Insert Shift:=xlDown
Range("A6").Select
ActiveCell.FormulaR1C1 = "Group Name"
Range("B6").Select
ActiveCell.FormulaR1C1 = "FSC"
Range("B6").Select
ActiveCell.FormulaR1C1 = "FSC #"

....and so on.
Is there something I need to define beforehand? Any assistance w/ this
would be GREATLY appreciated (I can't afford to lose anymore hair).

Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I've often gotten this error when I already had an instance of Excel
running.
When you finish with this portion of your code, do you explicitly close all
your Excel objects, Quit your Excel application, and set all Excel objects
to Nothing?

"dailem" <mi*********@ucphysicians.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I have a bit of code tied to a command button in Access that runs a
query then transfers it to a new Excel worksheet (& new file). It
works fine EVERY OTHER
TIME THAT I RUN IT....what the 'heck is going on? I get the following
error message on the odd runs:

Run-Time Error 1004

Method 'Columns' of object '_Global' failed
....the query results make it to the worksheet. The error occurs in my
section
of code that formats the worksheet once the data has been imported. I
have copied the applicable section of data below:

THIS IS WHERE I GET THE ERROR (EVERY OTHER TIME THAT I RUN IT)
Columns("A:A").EntireColumn.AutoFit
Rows("1:6").Select
Selection.Insert Shift:=xlDown
Range("A6").Select
ActiveCell.FormulaR1C1 = "Group Name"
Range("B6").Select
ActiveCell.FormulaR1C1 = "FSC"
Range("B6").Select
ActiveCell.FormulaR1C1 = "FSC #"

...and so on.
Is there something I need to define beforehand? Any assistance w/ this
would be GREATLY appreciated (I can't afford to lose anymore hair).

Nov 13 '05 #2

P: n/a
Well it took a lot of trial & error, but I finally got it working
correctly. I'm a rookie at VBA, so I had to dig a little further into
how to best accomplish what you suggest in your reply. I actually
modified my code to always refer to ranges or selections w/ the preface
of excel.application.....this eliminated excel.exe running even after I
shut the program down.
I appreciate your feedback to point me in the right direction.

Thanks Again MacDermott..............Mike D.

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.