473,769 Members | 4,601 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Macro to save query as Excel file

Please can anyone tell me how I can create a macro to save the results
of a query as an excel file? The query is called Student List and I
would like to save it to "My Documents".

We have had some problems with our database crashing. We would
therefore like another way to have access to basic student data and
thought we automatically save the results of this query when we close
Access.

Any suggestions on how we could do this would be really appreciated

Thanks a lot

Carl
Oxford UK
Nov 12 '05 #1
5 24204
Hi Carl

Create a command button on your form (without using the wizard) and in the
On Click event type the following;

On Error Resume Next
DoCmd.OuptputTo , "Student List", acFormatXLS, "C:\My
Documents\Stude nts.xls", False
For more details look at OutputTo in the help file.

Stewart
"Carl" <ca*********@ox mhc-tr.nhs.uk> wrote in message
news:83******** *************** ***@posting.goo gle.com...
Please can anyone tell me how I can create a macro to save the results
of a query as an excel file? The query is called Student List and I
would like to save it to "My Documents".

We have had some problems with our database crashing. We would
therefore like another way to have access to basic student data and
thought we automatically save the results of this query when we close
Access.

Any suggestions on how we could do this would be really appreciated

Thanks a lot

Carl
Oxford UK

Nov 12 '05 #2
Thanks Stewart. I couldn't get this to work but I was able to create a
macro and use the OutputTo action from there.

Please can you tell me if there is any way to automate this when a
user closes out of Access? And if so, does it matter if other users
have the database open at the same time?

TIA

Carl

"Stewart Allen" <sa****@REMOVET HISwave.co.nz> wrote in message news:<bn******* ***@news.wave.c o.nz>...
Hi Carl

Create a command button on your form (without using the wizard) and in the
On Click event type the following;

On Error Resume Next
DoCmd.OuptputTo , "Student List", acFormatXLS, "C:\My
Documents\Stude nts.xls", False
For more details look at OutputTo in the help file.

Stewart
"Carl" <ca*********@ox mhc-tr.nhs.uk> wrote in message
news:83******** *************** ***@posting.goo gle.com...
Please can anyone tell me how I can create a macro to save the results
of a query as an excel file? The query is called Student List and I
would like to save it to "My Documents".

We have had some problems with our database crashing. We would
therefore like another way to have access to basic student data and
thought we automatically save the results of this query when we close
Access.

Any suggestions on how we could do this would be really appreciated

Thanks a lot

Carl
Oxford UK

Nov 12 '05 #3
Are there any error messages when using the code? Remove the "on error
resume next" line and see if any error messages pop up. The DoCmd.OutputTo
line is on one line, the newreader has wrapped the code to the next line. If
you want Excel to open the newly created file, change the False to True.

Yes there is a way to do this automatically when Access closes. If you have
a switchboard (which should be the first form to open) place the
DoCmd.OutputTo line in the Unload event of the switchboard form. If you have
several users opening the databse at the same time, consider splitting the
database into 2; one holds the tables only and is placed on a server or
dedicated PC, and every user has their own copy of the user interface on
their own PCs. These contains all the forms, queries, reports etc and have
linked tables to the backend. Check this link for more details
http://members.iinet.net.au/~allenbrowne/ser-01.html

Stewart
"Carl" <ca*********@ox mhc-tr.nhs.uk> wrote in message
news:83******** *************** **@posting.goog le.com...
Thanks Stewart. I couldn't get this to work but I was able to create a
macro and use the OutputTo action from there.

Please can you tell me if there is any way to automate this when a
user closes out of Access? And if so, does it matter if other users
have the database open at the same time?

TIA

Carl

"Stewart Allen" <sa****@REMOVET HISwave.co.nz> wrote in message

news:<bn******* ***@news.wave.c o.nz>...
Hi Carl

Create a command button on your form (without using the wizard) and in the On Click event type the following;

On Error Resume Next
DoCmd.OuptputTo , "Student List", acFormatXLS, "C:\My
Documents\Stude nts.xls", False
For more details look at OutputTo in the help file.

Stewart
"Carl" <ca*********@ox mhc-tr.nhs.uk> wrote in message
news:83******** *************** ***@posting.goo gle.com...
Please can anyone tell me how I can create a macro to save the results
of a query as an excel file? The query is called Student List and I
would like to save it to "My Documents".

We have had some problems with our database crashing. We would
therefore like another way to have access to basic student data and
thought we automatically save the results of this query when we close
Access.

Any suggestions on how we could do this would be really appreciated

Thanks a lot

Carl
Oxford UK

Nov 12 '05 #4
Hi Stewart,

I have split the database so that the back end sits on the server and
everything else is in "My Documents". I am trying to add the code to
the Switchboard Unload Event. From the Properties window I clicked
next to On Unload
and then on the button with the three dots. This took me to the VBA
editor and I pasted the following

On Error Resume Next
DoCmd.OuptputTo , "Student List", acFormatXLS, "C:\My
Documents\Stude nts.xls", False
into the function that had been created to give:(the False is on the
same line as the DoCmd)

Private Sub Form_Unload(Can cel As Integer)
On Error Resume Next
DoCmd.OuptputTo , "Student List", acFormatXLS, "C:\My
Documents\Stude nts.xls", False

End Sub
I now get a Compile error:
Method or Data Member not found

when I try to close the database

Please can you offer any suggestions?

TIA
Carl

"Stewart Allen" <sa****@REMOVET HISwave.co.nz> wrote in message news:<bn******* ***@news.wave.c o.nz>...
Are there any error messages when using the code? Remove the "on error
resume next" line and see if any error messages pop up. The DoCmd.OutputTo
line is on one line, the newreader has wrapped the code to the next line. If
you want Excel to open the newly created file, change the False to True.

Yes there is a way to do this automatically when Access closes. If you have
a switchboard (which should be the first form to open) place the
DoCmd.OutputTo line in the Unload event of the switchboard form. If you have
several users opening the databse at the same time, consider splitting the
database into 2; one holds the tables only and is placed on a server or
dedicated PC, and every user has their own copy of the user interface on
their own PCs. These contains all the forms, queries, reports etc and have
linked tables to the backend. Check this link for more details
http://members.iinet.net.au/~allenbrowne/ser-01.html

Stewart
"Carl" <ca*********@ox mhc-tr.nhs.uk> wrote in message
news:83******** *************** **@posting.goog le.com...
Thanks Stewart. I couldn't get this to work but I was able to create a
macro and use the OutputTo action from there.

Please can you tell me if there is any way to automate this when a
user closes out of Access? And if so, does it matter if other users
have the database open at the same time?

TIA

Carl

"Stewart Allen" <sa****@REMOVET HISwave.co.nz> wrote in message

news:<bn******* ***@news.wave.c o.nz>...
Hi Carl

Create a command button on your form (without using the wizard) and in the On Click event type the following;

On Error Resume Next
DoCmd.OuptputTo , "Student List", acFormatXLS, "C:\My
Documents\Stude nts.xls", False
For more details look at OutputTo in the help file.

Stewart
"Carl" <ca*********@ox mhc-tr.nhs.uk> wrote in message
news:83******** *************** ***@posting.goo gle.com...
> Please can anyone tell me how I can create a macro to save the results
> of a query as an excel file? The query is called Student List and I
> would like to save it to "My Documents".
>
> We have had some problems with our database crashing. We would
> therefore like another way to have access to basic student data and
> thought we automatically save the results of this query when we close
> Access.
>
> Any suggestions on how we could do this would be really appreciated
>
> Thanks a lot
>
> Carl
> Oxford UK

Nov 12 '05 #5
This sounds like a referencing problem. What version of access are you
using? While in the VBA editor goto Tools>Reference s and list all the items
that are ticked. Also while you're in the editor goto Debug and click
Compile. What is the line of code that is highlighted in yellow? Copy and
paste that block of code into your reply message and indicate which line was
highlighted.

Stewart
"Carl" <ca*********@ox mhc-tr.nhs.uk> wrote in message
news:83******** *************** ***@posting.goo gle.com...
Hi Stewart,

I have split the database so that the back end sits on the server and
everything else is in "My Documents". I am trying to add the code to
the Switchboard Unload Event. From the Properties window I clicked
next to On Unload
and then on the button with the three dots. This took me to the VBA
editor and I pasted the following

On Error Resume Next
DoCmd.OuptputTo , "Student List", acFormatXLS, "C:\My
Documents\Stude nts.xls", False
into the function that had been created to give:(the False is on the
same line as the DoCmd)

Private Sub Form_Unload(Can cel As Integer)
On Error Resume Next
DoCmd.OuptputTo , "Student List", acFormatXLS, "C:\My
Documents\Stude nts.xls", False

End Sub
I now get a Compile error:
Method or Data Member not found

when I try to close the database

Please can you offer any suggestions?

TIA
Carl

"Stewart Allen" <sa****@REMOVET HISwave.co.nz> wrote in message

news:<bn******* ***@news.wave.c o.nz>...
Are there any error messages when using the code? Remove the "on error
resume next" line and see if any error messages pop up. The DoCmd.OutputTo line is on one line, the newreader has wrapped the code to the next line. If you want Excel to open the newly created file, change the False to True.

Yes there is a way to do this automatically when Access closes. If you have a switchboard (which should be the first form to open) place the
DoCmd.OutputTo line in the Unload event of the switchboard form. If you have several users opening the databse at the same time, consider splitting the database into 2; one holds the tables only and is placed on a server or
dedicated PC, and every user has their own copy of the user interface on
their own PCs. These contains all the forms, queries, reports etc and have linked tables to the backend. Check this link for more details
http://members.iinet.net.au/~allenbrowne/ser-01.html

Stewart
"Carl" <ca*********@ox mhc-tr.nhs.uk> wrote in message
news:83******** *************** **@posting.goog le.com...
Thanks Stewart. I couldn't get this to work but I was able to create a
macro and use the OutputTo action from there.

Please can you tell me if there is any way to automate this when a
user closes out of Access? And if so, does it matter if other users
have the database open at the same time?

TIA

Carl

"Stewart Allen" <sa****@REMOVET HISwave.co.nz> wrote in message

news:<bn******* ***@news.wave.c o.nz>...
> Hi Carl
>
> Create a command button on your form (without using the wizard) and in
the
> On Click event type the following;
>
> On Error Resume Next
> DoCmd.OuptputTo , "Student List", acFormatXLS, "C:\My
> Documents\Stude nts.xls", False
>
>
> For more details look at OutputTo in the help file.
>
> Stewart
>
>
> "Carl" <ca*********@ox mhc-tr.nhs.uk> wrote in message
> news:83******** *************** ***@posting.goo gle.com...
> > Please can anyone tell me how I can create a macro to save the

results > > of a query as an excel file? The query is called Student List and I > > would like to save it to "My Documents".
> >
> > We have had some problems with our database crashing. We would
> > therefore like another way to have access to basic student data and > > thought we automatically save the results of this query when we close > > Access.
> >
> > Any suggestions on how we could do this would be really appreciated > >
> > Thanks a lot
> >
> > Carl
> > Oxford UK

Nov 12 '05 #6

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

Similar topics

2
2899
by: LBT | last post by:
Hi experts, With response.contenttype = "application/vnd.ms-excel", I can easily export my data to Excel which is embeded and shown within a browser. If I'm going to save the Excel file through ASP programming, which method can I use? I need to save the data to Excel file with dynamic name (the file name should contain key values and appended with system datetime). Thanks a lot
0
1039
by: Ed Bangle | last post by:
Hi everyone, I desparately need help. I have an excel file that I cannot convert to XML because of the VB code wrapped into the file and the calculations in each cell. I need to attach all of the elements of the excel file into a web page for someone to launch, make changes and save the excel file onto there desktop. Eventually, the save function will be replaced with an update or insert function into SQL Server.
7
4915
by: mattmerc | last post by:
Hi all, We have all seen lot of method for exporting datagrids to Excel. I have a slightly different need. I think it should be easy to accomplish but I am not sure how. I would like when a user clicks a button for exporting a datagrid, that the excel file is saved on the server and that it DOES NOT prompt the user to open or save. Here is the code I am using for standard export that prompts the user. Thanks all. Dim...
7
11150
by: alwayssmiling | last post by:
Hi frends, In my application, a class supports backend processing. In this class im creating a new excel sheet and im inserting some data into this excel sheet, and im trying to save the file with the help of methods SAVE AND SAVE AS. But it is displaying save dialog while it is saving. But since it is backend class i dont want that dialog. Is there any other way to save the excel file without displaying save dialog . PLZ HELP ME . ...
1
5168
by: NBKMNDN | last post by:
Hi frends, In my C# application im creating a new excel sheet and im inserting some data into this excel sheet, and im trying to save the file with the help of method SAVE AS. But it doesnot displays save dialog while it is saving. how to save the excel file by displaying save dialog in c#. THANK U .
0
3946
by: =?Utf-8?B?Tml5YXpp?= | last post by:
Hi all, Does anyone know how to embed the Excel file in VB.NET 2005 Resources? Here is what I am doing at the moment: 1) In my VB.NET 2005 project code I load the excel with it path into string as: ------------------------------------------------------------------------------------------------ Dim fileNameXL As String = "_MYEXCEL_REPORTS.XLS" Dim pathNameXL As String = "\EXCEL_TEMP\"
7
18342
by: shantanu | last post by:
Hi all i am trying to save a excel file as a tab delimited text file. can i do it some how? i using the code _sheet1.SaveAs(@"C:\PRP \PRPTemp.txt",Excel.XlFileFormat.xlTextWindows ,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing); Kindly assist
1
2112
roswara
by: roswara | last post by:
Dear all, Currently, I am working on a project to make a web-based application using ASP 2.0 and C#. This application will ask user to input for an excel file which has graphs in it. Then the application will grab the graph as image file, and this image will be displayed as thumbnail in the page. Is it possible to accomplish this feature? If it is possible, would you please tell me how? And if it is not possible, why?
4
21723
by: Rodthemod | last post by:
Hi All I wish to send excel files to other company staff - but save the file as values (so not showing all my formulae links etc ) Please help Thanks in advance Kind regards
1
2028
by: Happy Zoe | last post by:
Can anyone help me for this? I am going to open an excel file when click a hyperlink using asp. But when i click the hyperlink, it can't be open. If i delete the macro inside the excel file, it can be open......So i think the problem should be the excel macro.....!!! Please reply me if u know the answer...thank you very much!
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9997
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8873
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.