Solved

how to export the contents of a subdatasheet to excel using vba

Posted on 2008-06-11
5
1,177 Views
Last Modified: 2013-11-27
Experts, right now am using VBA to automatically run a query that creates a table with subdatasheets. The program then automatically exports the primary table to excel. My question is, how do i reference the subdatasheets so that i can automatically export these to excel as well? Below is the code i am currently running to export the primary sheet
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "PRIMARYTABLE", sFn, True, "6B_LinkFileReferences!A1:J1"

Open in new window

0
Comment
Question by:Forensicon
  • 2
5 Comments
 
LVL 3

Expert Comment

by:BitRunner303
ID: 21762837
If the subdatasheets are queries or tables they can be exported using the same function.
If it's a form or report though, use the DoCmd.OutputTo command to export:

e.g.

DoCmd.OutputTo acOutputForm,"MySubDataSheet",acFormatXLS,"C:\MyFile.xls",True
0
 

Author Comment

by:Forensicon
ID: 21763048
How do i know what the subdatasheet name is, i can't figure out where/if i named it? Below is the code i use to create the subdatasheet.
SetFieldProperty CurrentDb.TableDefs![LNK_Link Files grouped by Serial Number with MinMax Dates], "SubdatasheetName", dbText, "LNK_Link Files by Link File Name"

SetFieldProperty CurrentDb.TableDefs![LNK_Link Files grouped by Serial Number with MinMax Dates], "LinkChildFields", dbText, "Serial"

SetFieldProperty CurrentDb.TableDefs![LNK_Link Files grouped by Serial Number with MinMax Dates], "LinkMasterFields", dbText, "Serial"

Open in new window

0
 
LVL 3

Accepted Solution

by:
BitRunner303 earned 500 total points
ID: 21763102
Look in your Forms tab, usually if you create a SubDatasheet by the Wizards it'll create a separate Form object for it.

In this case though wouldn't it be called "LNK_Link Files by Link File Name" as you specified?

However, what I would probably do is just design a query linking the data, then do a TransferSpreadsheet on the query to export it to Excel that's a much cleaner method.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now