Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / December 2005

Tip: Looking for answers? Try searching our database.

save query as excel 97 using VB

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark - 19 May 2005 02:31 GMT
Hello all,

First let me tell you what I'm trying to do and let me know if there is a
better way.

I am wanting to be able to click on a button and have it export a query and
save it to the an excel format (97), without having to do anything else.  It
would also be nice to be able to have it let me select where it is going to
save, but that might just be another question for later.

I can select the query then click on the "save Expot", but really would like
this to be a one button push process.

Is there a way in VB to save as and Excel format?  I have saved files before
in code using csv, but would like to save as excel if possible.
Mark - 19 May 2005 03:24 GMT
Hello all again,

I found some of my answer by using a wizard for button's.  However it
doesn't do one thing.  I Would like to keep a format on the excel sheet, i.e.
color, size, etc.  Is this possible ?  Here is the code it created.  Once
clicked it pops up a box of what format (Excel, Rich Format, etc) I would
like, but then it over writes everything.

Dim stDocName As String

   stDocName = "rpTtlConx"
   DoCmd.OutputTo acReport, stDocName

> Hello all,
>
[quoted text clipped - 11 lines]
> Is there a way in VB to save as and Excel format?  I have saved files before
> in code using csv, but would like to save as excel if possible.
John Vinson - 19 May 2005 04:06 GMT
>Is there a way in VB to save as and Excel format?  I have saved files before
>in code using csv, but would like to save as excel if possible.

Take a look at the Help for "TransferSpreadsheet" - that's the VBA
method which can export a recordset to an Excel workbook.

                 John W. Vinson[MVP]    
Mark - 19 May 2005 04:45 GMT
Thanks!  That is what I was looking for.

> >Is there a way in VB to save as and Excel format?  I have saved files before
> >in code using csv, but would like to save as excel if possible.
[quoted text clipped - 3 lines]
>
>                   John W. Vinson[MVP]    
Dylan Moran - 19 May 2005 05:39 GMT
Fully tested and functional.
Attach code to onclick of command button.

Dim strFilter As String
Dim strSaveFileName As String

 'Display dialog
 strFilter = ahtAddFilterItem(strFilter, _
     "Excel Files (*.XLS)", "*.XLS")
 strSaveFileName = ahtCommonFileOpenSave( _
     OpenFile:=False, _
     Filter:=strFilter, _
     Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY)

 If Len(strSaveFileName) > 0 Then 'User entered a filename
   DoCmd.TransferSpreadsheet acExport, _
       acSpreadsheetTypeExcel8, "EnterQueryNameHere", _
       strSaveFileName
 Else 'User pressed Cancel
   'Do nothing

 End If

Signature

I may not know VBA inside out, but from the outside I am looking in.
Dylan Moran - Melbourne Australia

> Thanks!  That is what I was looking for.
>
[quoted text clipped - 5 lines]
> >
> >                   John W. Vinson[MVP]    
Hyperactive - 22 Jun 2005 19:10 GMT
Can you give me an idea of how I could do this using VB.NET in a windows app,
pulling from a database query? Thanks for your help!

> Fully tested and functional.
> Attach code to onclick of command button.
[quoted text clipped - 28 lines]
> > >
> > >                   John W. Vinson[MVP]    
Dylan Moran - 23 Jun 2005 00:58 GMT
No, sorry. No idea.

> Can you give me an idea of how I could do this using VB.NET in a windows app,
> pulling from a database query? Thanks for your help!
[quoted text clipped - 31 lines]
> > > >
> > > >                   John W. Vinson[MVP]    
Justin - 09 Dec 2005 14:49 GMT
If you use this code, you must download a module which Dylan's code is
referencing to.   Maybe he forgot to mention?

go to http://www.mvps.org/access/api/api0001.htm

and copy the code from

'******Code Start******

to

'++++++Code End******

and paste it in a new module.  Save it as anything and then insert Dylan's
code to your control.  It will now work.

> Fully tested and functional.
> Attach code to onclick of command button.
[quoted text clipped - 28 lines]
> > >
> > >                   John W. Vinson[MVP]    
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.