A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

'output to' question



 
 
Thread Tools Display Modes
  #1  
Old June 1st, 2008, 09:46 PM posted to microsoft.public.access.gettingstarted
steve goodrich
external usenet poster
 
Posts: 132
Default 'output to' question

I have a query that I transfer to a text file using the 'Transfer text'
option in a macro. I have this macro assigned to the close event on my form
so when the database is closed the text file is updated and I don't get any
prompts saying that the file already exists - do you want to overwrite.,
works great,

I would like to do transfer the query into an Excel spreadsheet instead of a
text file. I am using the 'Output to' option when creating the macro -
output format Excel, and that also works great with one exception. I am
prompted to overwrite the existing file each time the macro runs, I.e. every
time I close the database.

My question:
Can I make it so the Excel file is updated automatically without me being
prompted, the same way the Transfer Text macro works when creating a text
file.

Many thanks

Steve


  #2  
Old June 1st, 2008, 10:53 PM posted to microsoft.public.access.gettingstarted
Jeanette Cunningham
external usenet poster
 
Posts: 2,190
Default 'output to' question

Steve,
being prompted is generally a good idea in most situations.
To avoid the prompt, you can check if the file already exists and delete it
before you run the outputto macro.
This is vba code, there are no built in macro functions to delete a file.
However macros do have the ability to run a vba function - it is called Run
Code.
Put the following code in a new module (create a new module in the modules
section of the database window)
For the macro that runs the code, the name of the function to call is
DeleteXLFile
---------------------------
Public Function DeleteXLFile
Dim strPathAndNameOfFile as String

strPathAndNameOfFile = "C:\MyFileName"

If Len(Dir(strPathAndNameOfFile))0 Then
Kill strPathAndNameOfFile
End If
End Function
------------------------------

strPathAndNameOfFile is the file name including extension and full path to
the file


Jeanette Cunningham -- Melbourne Victoria Australia


"Steve Goodrich" wrote in message
. ..
I have a query that I transfer to a text file using the 'Transfer text'
option in a macro. I have this macro assigned to the close event on my
form so when the database is closed the text file is updated and I don't
get any prompts saying that the file already exists - do you want to
overwrite., works great,

I would like to do transfer the query into an Excel spreadsheet instead of
a text file. I am using the 'Output to' option when creating the macro -
output format Excel, and that also works great with one exception. I am
prompted to overwrite the existing file each time the macro runs, I.e.
every time I close the database.

My question:
Can I make it so the Excel file is updated automatically without me being
prompted, the same way the Transfer Text macro works when creating a text
file.

Many thanks

Steve



  #3  
Old June 2nd, 2008, 12:10 AM posted to microsoft.public.access.gettingstarted
steve goodrich
external usenet poster
 
Posts: 132
Default 'output to' question

Jeanette,
It worked perfectly, many thanks
Steve
"Jeanette Cunningham" wrote in message
...
Steve,
being prompted is generally a good idea in most situations.
To avoid the prompt, you can check if the file already exists and delete
it before you run the outputto macro.
This is vba code, there are no built in macro functions to delete a file.
However macros do have the ability to run a vba function - it is called
Run Code.
Put the following code in a new module (create a new module in the modules
section of the database window)
For the macro that runs the code, the name of the function to call is
DeleteXLFile
---------------------------
Public Function DeleteXLFile
Dim strPathAndNameOfFile as String

strPathAndNameOfFile = "C:\MyFileName"

If Len(Dir(strPathAndNameOfFile))0 Then
Kill strPathAndNameOfFile
End If
End Function
------------------------------

strPathAndNameOfFile is the file name including extension and full path
to the file


Jeanette Cunningham -- Melbourne Victoria Australia


"Steve Goodrich" wrote in message
. ..
I have a query that I transfer to a text file using the 'Transfer text'
option in a macro. I have this macro assigned to the close event on my
form so when the database is closed the text file is updated and I don't
get any prompts saying that the file already exists - do you want to
overwrite., works great,

I would like to do transfer the query into an Excel spreadsheet instead
of a text file. I am using the 'Output to' option when creating the
macro - output format Excel, and that also works great with one
exception. I am prompted to overwrite the existing file each time the
macro runs, I.e. every time I close the database.

My question:
Can I make it so the Excel file is updated automatically without me being
prompted, the same way the Transfer Text macro works when creating a text
file.

Many thanks

Steve





 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:18 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.