Analyze it with Excel

Hello,
I would like the ability to add this to a form on a button click. I know of the "output to" and the "transfer spreadsheet", but i have a form that is datasheet view with 3 subforms in datasheet view, and I would like it to export to excel with those subforms grouped in (with the plus sybols for expanding records... just like in datasheet view.
Any help is much appreciated.
Thanks
a260148Asked:
Who is Participating?
 
harfangCommented:
Hi,

> ... a docmd.menu item... etc for the "analyze it with Microsoft Excel".

it's: RunCommand acCmdOutputToExcel

However, it's not what you want. You either want the details from the current record from the main form, and all three subform datasheets, or even all records from the main form, each along their corresponding three subform datasheets. In any case, this will require a bit of programming.

First, use simple copy-.paste to create the speadsheet you want. Where do you want each subdatasheet data to appear: one below the other, side-by-side, on different worksheets? How do you intermix data from the main form with the data from the subforms, etc.

Once you have a clear vision of what you want to create, start programming the export function.

The basic source will be the recordsets of the form and subforms. The basic tool will be the .CopyFromRecordset method of the Excel.Range object. You can either copy an entire recordset at once, or just the current record, or any preset number of records.

Finally, for the cosmetics (the data grouping buttons) you can use Excel's macro recorder to generate templates of what you need to acheive.

I hope this helps.
(°v°)
0
 
a260148Author Commented:
Another point to add is that my recordset has to many records to use "output to"... and i can't use transfer spreadsheet unless it's a table. It would be great if their was a docmd.menu item... etc for the "analyze it with Microsoft Excel".
Thanks
0
 
Rey Obrero (Capricorn1)Commented:
try this

Private Sub cmdAnalyze_Click()

CommandBars("Menu Bar").Controls("Tools").Controls("Office Links").Controls("Analyze It With Microsoft Office Excel").accDoDefaultAction

End Sub
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
a260148Author Commented:
run-time error 5 - invalid procedure call or agrument
0
 
Rey Obrero (Capricorn1)Commented:

huh...

just tried it with the Northwind database Orders form and it is working.
0
 
a260148Author Commented:
i have the dbwindow hidden... think that may be it?
0
 
a260148Author Commented:
Ok, i unhid the window and it does give me the option now, but when I export... it only grabs the main form, which is just a few textboxes... i need it to grab the subforms and such??
0
 
Rey Obrero (Capricorn1)Commented:
check the record source of  your form, subform .

i believe it will only export to excel the record source of the form.

check the Northwind Orders form, the record source Orders Qry is the one being exported to excel
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.