472,348 Members | 1,236 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,348 software developers and data experts.

Finding Real Worksheet Name After Access Export

[Sorry for the cross-post, but it may be an issue either group may
have the answer to through experience.]

I'm working on some procedures where Access queries are exported to
Excel, and then later on, those same workbooks are openned, and I need
to target a specific original sheet. Sometimes there will be multiple
sheets in the same workbook, sometimes only a single tab.

The issue is this: Save query "XLTest - qryExport" to file and the
worksheet name becomes "XLTest___qryExport" (three underscores). I
have a generic procedure which performs the export, so if exported
multiple times, there is no error. However, if saved manually (File |
Save As...), I'll get "The object 'XLTest - qryExport' already
exists...".

Looking at Worksheet.Name in Excel, I can find "XLTest___qryExport".
I've tried browsing the entire object tree but don't see "XLTest -
qryExport" anywhere.

Is it there, or is Access throwing out this message after interpreting
a message thrown back from trying to save the query object?

Thanks in advance. Again, sorry for the cross-post.

Anthony.
Nov 13 '05 #1
4 3243
ac*******@railvan.com (Anthony Cuttitta Jr.) wrote ...
I'm working on some procedures where Access queries are exported to
Excel, and then later on, those same workbooks are openned, and I need
to target a specific original sheet.

Save query "XLTest - qryExport" to file and the
worksheet name becomes "XLTest___qryExport" (three underscores).

Looking at Worksheet.Name in Excel, I can find "XLTest___qryExport".
I've tried browsing the entire object tree but don't see "XLTest -
qryExport" anywhere.
Here's my test:

Export data from Jet .mdb to Excel .xls:

SELECT
MyIntCol
INTO
[Excel 8.0;HDR=YES;Database=C:\Anthony.xls;].[XLTest - qryExport]
FROM
MyTable
;

Open the newly-created workbook in the Excel UI. It contains one sheet
only. Switch to the Visual Basic Editor and in the Immediate Window:

? ThisWorkbook.Worksheets(1).Name
XLTest___qryExport

? ThisWorkbook.Worksheets("XLTest___qryExport").Inde x
1

? ThisWorkbook.Worksheets(1).CodeName
Sheet1

The sheet code module appears in the VBE Project Explorer as
'<<CodeName>> (<<Name>>)', hence I see it as 'Sheet1
(XLTest___qryExport)'.

All the above results are as I would expect, bearing in mind that
Jet's SELECT..INTO syntax creates a new defined Name and that Excel
does not allow space or hyphen characters in the defined Name's name.
I
have a generic procedure which performs the export, so if exported
multiple times, there is no error. However, if saved manually (File |
Save As...), I'll get "The object 'XLTest - qryExport' already
exists...".


I'm not an MS Access user myself but from what I've read in the
newsgroups I'm going to take a guess that you are using
TransferSpreadsheet (or similar) in VBA code. From reading I also
infer that, under the covers, TransferSpreadsheet issues a DROP TABLE
before issuing a SELECT..INTO, which would explain why you are able
re-run the same code without error. You could probably reproduce
'manually' if you did the DROP TABLE yourself before saving.

All that said, I'm not sure what you are looking for as regards a
solution, so here are some suggestions:

- Use an Excel table name that uses only alphanumeric and underscore
characters
- Don't trust MS Access to run hidden code (especially when that code
is a DROP TABLE!); instead, write your own sql code, preferable using
DROP TABLE, CREATE TABLE and INSERT INTO..SELECT syntax (in that
order) or perhaps CREATE TABLE then SELECT..INTO.

Jamie.

--
Nov 13 '05 #2
Access gives you a failure message using the term
'XLTest - qryExport' because that is what you tried to
export, not because Excel has a sheet of that name.

(david)
"Anthony Cuttitta Jr." <ac*******@railvan.com> wrote in message
news:66**************************@posting.google.c om...
[Sorry for the cross-post, but it may be an issue either group may
have the answer to through experience.]

I'm working on some procedures where Access queries are exported to
Excel, and then later on, those same workbooks are openned, and I need
to target a specific original sheet. Sometimes there will be multiple
sheets in the same workbook, sometimes only a single tab.

The issue is this: Save query "XLTest - qryExport" to file and the
worksheet name becomes "XLTest___qryExport" (three underscores). I
have a generic procedure which performs the export, so if exported
multiple times, there is no error. However, if saved manually (File |
Save As...), I'll get "The object 'XLTest - qryExport' already
exists...".

Looking at Worksheet.Name in Excel, I can find "XLTest___qryExport".
I've tried browsing the entire object tree but don't see "XLTest -
qryExport" anywhere.

Is it there, or is Access throwing out this message after interpreting
a message thrown back from trying to save the query object?

Thanks in advance. Again, sorry for the cross-post.

Anthony.

Nov 13 '05 #3
ja**********@xsmail.com (Jamie Collins) wrote in message news:<2e**************************@posting.google. com>...
ac*******@railvan.com (Anthony Cuttitta Jr.) wrote ... [snip] - Use an Excel table name that uses only alphanumeric and underscore
characters
- Don't trust MS Access to run hidden code (especially when that code
is a DROP TABLE!); instead, write your own sql code, preferable using
DROP TABLE, CREATE TABLE and INSERT INTO..SELECT syntax (in that
order) or perhaps CREATE TABLE then SELECT..INTO.

Jamie.

--


I've already resigned myself to the first point and am implimenting
it. Thanks for your response!
Nov 13 '05 #4
Gotcha. So it's as I assumed. It made the attempt, received an
error, then sent back a response with using the name IT was trying,
not what it found on the other end.

"david epsom dot com dot au" <david@epsomdotcomdotau> wrote in message news:<41**********************@news.syd.swiftdsl.c om.au>...
Access gives you a failure message using the term
'XLTest - qryExport' because that is what you tried to
export, not because Excel has a sheet of that name.

(david)
"Anthony Cuttitta Jr." <ac*******@railvan.com> wrote in message
news:66**************************@posting.google.c om...
[Sorry for the cross-post, but it may be an issue either group may
have the answer to through experience.]

I'm working on some procedures where Access queries are exported to
Excel, and then later on, those same workbooks are openned, and I need
to target a specific original sheet. Sometimes there will be multiple
sheets in the same workbook, sometimes only a single tab.

The issue is this: Save query "XLTest - qryExport" to file and the
worksheet name becomes "XLTest___qryExport" (three underscores). I
have a generic procedure which performs the export, so if exported
multiple times, there is no error. However, if saved manually (File |
Save As...), I'll get "The object 'XLTest - qryExport' already
exists...".

Looking at Worksheet.Name in Excel, I can find "XLTest___qryExport".
I've tried browsing the entire object tree but don't see "XLTest -
qryExport" anywhere.

Is it there, or is Access throwing out this message after interpreting
a message thrown back from trying to save the query object?

Thanks in advance. Again, sorry for the cross-post.

Anthony.

Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dayron | last post by:
Hi, I would like export the records retrieved from database to excel worksheets. unfortunately, each worksheet will support until 65535 records...
3
by: sridevi | last post by:
Hello How to export data from ms-access database to excel worksheet using ASP. mainly i need to export data to multiple worksheets. it is very...
2
by: Anne Sachleben via AccessMonster.com | last post by:
I am using the TransferSpreadsheet function to export a query result to a specific worksheet in an Excel file titled "report". I want the result to...
1
by: Jim | last post by:
This should really be simple, but I can't figure it out. I have some VB that exports a table in an Excel format ("C:\NewReport.xls"). After the...
5
by: hmiller | last post by:
Hey there folks: I have been trying to get this work for about a week now. I'm new to VBA... I am trying to transfer a populated table in...
1
by: smaczylo | last post by:
Hello, I've recently been asked to work with Microsoft Access, and while I feel quite comfortable with Excel, I'm at a complete loss with...
0
by: blainegray | last post by:
Greetings This is one of those Access is not closing Excel problems. The first time through the code works fine. The second time there is a...
2
by: prinsipe | last post by:
Hi guys, i'm able to export data to an excel from my asp .net page, i can even create multiple worksheets. the problem is, i can not specify where...
1
by: sayedul | last post by:
Hi, I can access data from xls file using OpenDataSource. But if the worksheet name starts with numeric character it gives error. Scripts are as...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.