Exporting to Excel Datasheet Contents (and More)

Hi,

I have a datasheet (within the frame of a larger form - for presentation purposes).

I may filter the 20,000 rows in the datasheet down to a couple of hundred (using standard Acess Datasheet functionality).

My Question Part One:  What is the best (with easy VBA is poss) way to export the (filtered) contents of my datasheet to Excel.

My Question Part Two: I will want to expand the export to include other (related) data other that what is displayed on the datasheet.  How do I do this (via a query I presume)

Patrick O'DeaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale FyeOwner, Developing Solutions LLCCommented:
Have not done this, but you might try something like the following (untested).  Add a command button (cmd_Export) to the outer form.  Include code that looks something like:

Private Sub cmd_Export_Click

    dim xl as object     'or Excel.application if you have a reference to Excel in your project
    dim wbk as object
    dim sht as object
    dim rs as DAO.Recordset

    set xl = createobject("Excel.Application")
    xl.visible = true
    set wbk = xl.workbooks.add
    set sht = wbk.sheets(1)
    sht.activate

    set rs = me.sub_datasheet.form.recordsetclone
    sht.Range("A2").copyfromrecordset rs

    set sht = nothing
    set wbk = nothing
    set xl = nothing

End Sub
McOzCommented:
Part One: The easiest is simply to go to the "External Data" tab, click "Excel" in the export section, and choose where to save the resulting file. It gives you options to preserve formatting, etc.

Part Two: You need to make a query which displays the related data as you want it, then simply repeat the steps above from your query for the same result.

Good luck!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Patrick O'DeaAuthor Commented:
thanks.  I took the advice!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.