473,378 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

OutputTo using dynamic filenames (date)

benchpolo
142 100+
I wrote a funtion in VBA OutputTo an excel file using dynamic filename.

Table: contact
Filename format: contact_10292007.xls
Code:

Expand|Select|Wrap|Line Numbers
  1. Function outfile()
  2.     Dim stbl As String
  3.     stbl = "Contact"
  4.     DoCmd.OutputTo acOutputTable, stbl, acFormatXLS, "c:\temp\contact_" & Now() & ".xls"
  5. End Function
  6.  
I am calling this function from a Macro RUNCODE, but when I execute the macro I am getting the error below,

"ScorTab can't save the output data to a file you've selected".

Note: ScorTab is the db name.
Oct 29 '07 #1
3 4616
Rabbit
12,516 Expert Mod 8TB
This is what Now() returns:
10/29/2007 10:34:28 AM
That contains characters you can't use in a file name.

This is what you want returned:
10292007

So this is what you use:
Expand|Select|Wrap|Line Numbers
  1. Format(Now(), "mmddyyyy")
  2.  
However, this doesn't work well for keeping files in order.
So you might want to use:
Expand|Select|Wrap|Line Numbers
  1. Format(Now(), "yyyymmdd")
  2.  
Oct 29 '07 #2
benchpolo
142 100+
After doing trial & errors on the module code here it what I came out with

Expand|Select|Wrap|Line Numbers
  1. Function outfile()
  2.     Dim stbl As String
  3.     stbl = "Contact"
  4.     DoCmd.OutputTo acOutputTable, stbl, acFormatXLS, "c:\temp\contact_" & Format(Now(), "yyyymmdd") & "_" & Format(Time(), "hhmmss") & ".xls"
  5. End Function
  6.  
Output: contact_20071029_102322.xls

Where the filename is "contact_" and the date is "20071029_" and time is "102322.xls".

Thanks for your help.
Oct 29 '07 #3
Rabbit
12,516 Expert Mod 8TB
Not a problem. Please use Code tags in the future.
Oct 29 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: CountScubula | last post by:
Ok, I just wrote some functions last night for a few people, I posted them up for whom ever wants it (free) http://www.gzentools.com/gzimg.php It is simple a way to spit out thumbs, or resized...
5
by: deko | last post by:
When trying to export a table: DoCmd.OutputTo acOutputTable, "tblOutput", strFile I get an error: Error Number 2282: The format in which you are attempting to output the current object is...
5
by: Mal | last post by:
Hi, I have a button on a form that outputs a report to word. While it has been working well for a while, today it is not. The behaviour now is that it endlessly outputs pages to word. There...
2
by: fordesky | last post by:
Gday, I have a set of Access 2000 tables that I would like to export into a MS Word 2000 template at specific bookmark locations that I've set up. Would anyone know the code to achieve...
1
by: Ryan | last post by:
Hello. I was hoping that someone may be able to assist with an issue that I am experiencing. I have created an Access DB which imports an Excel File with a particular layout and field naming. ...
5
by: sara | last post by:
I have reports that run from a form where the user can choose a date range, or they run automatically for a week in the "Weekly Reports" option. I created 2 queries and 2 reports - one query...
5
by: dancole42 | last post by:
I have a question regarding the DoCmd.OutputTo function. I have an invoice report that shows all of the invoices for a particular date. I want to create a button that will export each page of...
2
by: Jim Devenish | last post by:
I have a report which can be displayed on the screen with: DoCmd.OpenReport "RemittanceAdvice",acViewNormal,,"PaymentID = " & paymentRecID I now wish to create a snapshot of this, using the...
2
by: jmartmem | last post by:
Greetings, I have several Access 2007 reports that I regularly export to individual PDF flat files on a web server. I've successfuly created a module sub to export the reports using the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.