I have created a database that has over 70 queries and over 40k
records. I used the OutputTo action to export the queries to Excel. I
would like the functionality of adding the date (Month-YY) to each of
the Excel file names as they are exported. It seems that the OutputTo
action only allows for predetermined names or a prompt for each file. I
do not want to type the file names 70+ times and renaming each of the
..xls files afterwards is a pain. Can anyone help me to achieve this
type of output?
Query_name1 - Month-YR.xls
Query_name2- Month-YR.xls
Query_name3- Month-YR.xls
Etc.
I think this formula closely fits my needs:
"MyFileName" & "_" & Format(Date(), "yyyymmdd") * ".xls"
Unfortunately, I know nothing about Visual Basic. If the only method of
achieving my goal is using VB, I could use a few pointers.
Many thanks,
Mark 6 2606
How about something like this?
Public Sub ExportQueriesToExcel()
Dim qdf As DAO.QueryDef
'---walk the querydefs collection (the queries in your db)
For Each qdf In DBEngine(0)(0).QueryDefs
'---I'm leaving out the ones I don't want to export:
'----Export only select queries.
If Left$(qdf.Name, 1) <"~" And Left$(qdf.SQL, 6) = "SELECT"
And _ InStr(1,
qdf.SQL, "INTO") = 0 Then
Debug.Print "Exporting " & qdf.Name & "..."
DoCmd.TransferSpreadsheet acExport,
acSpreadsheetTypeExcel9, qdf.Name, "C:\test\" & qdf.Name & "-" &
Format$(Date, "mm-dd-yyyy") & ".xls"
End If
Next qdf
Set qdf = Nothing
MsgBox "Done" ' not necessary... just feedback.
End Sub
Not pretty, but it works. the testing the SQL property is just to make
sure no action queries get run by accident.
HTH,
Pieter
On 20 Jul 2006 20:33:50 -0700, "ninrulz" <ni********@hotmail.com>
wrote:
Check out DoCmd.TransferSpreadsheet. It allows you to specify a
filename.
Dim varQueries As Variant
Dim varQuery As Variant
varQueries = Array("Query_name1 - Month-YR.xls", "Query_name2-
Month-YR.xls", "Query_name3- Month-YR.xls") 'etc.
For Each varQuery In varQueries
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9,
varQuery, varQuery & Format$(Date, "yyyymmdd") & ".xls", True
Next
-Tom.
>I have created a database that has over 70 queries and over 40k records. I used the OutputTo action to export the queries to Excel. I would like the functionality of adding the date (Month-YY) to each of the Excel file names as they are exported. It seems that the OutputTo action only allows for predetermined names or a prompt for each file. I do not want to type the file names 70+ times and renaming each of the .xls files afterwards is a pain. Can anyone help me to achieve this type of output?
Query_name1 - Month-YR.xls Query_name2- Month-YR.xls Query_name3- Month-YR.xls Etc.
I think this formula closely fits my needs:
"MyFileName" & "_" & Format(Date(), "yyyymmdd") * ".xls"
Unfortunately, I know nothing about Visual Basic. If the only method of achieving my goal is using VB, I could use a few pointers.
Many thanks, Mark
On 20 Jul 2006 21:08:00 -0700, pi********@hotmail.com wrote:
Or rather than testing for the word "Select" at the beginning of the
SQL property (which breaks down if you have specified the data types
of your parameters), why not test the Type property:
if qdf.Type = dbQSelect or qdf.Type = dbQSetOperation then
'it's a Select or Union query
-Tom.
>How about something like this?
Public Sub ExportQueriesToExcel()
Dim qdf As DAO.QueryDef
'---walk the querydefs collection (the queries in your db)
For Each qdf In DBEngine(0)(0).QueryDefs
'---I'm leaving out the ones I don't want to export:
'----Export only select queries.
If Left$(qdf.Name, 1) <"~" And Left$(qdf.SQL, 6) = "SELECT" And _ InStr(1,
qdf.SQL, "INTO") = 0 Then
Debug.Print "Exporting " & qdf.Name & "..."
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, qdf.Name, "C:\test\" & qdf.Name & "-" & Format$(Date, "mm-dd-yyyy") & ".xls"
End If
Next qdf
Set qdf = Nothing
MsgBox "Done" ' not necessary... just feedback. End Sub
Not pretty, but it works. the testing the SQL property is just to make sure no action queries get run by accident.
HTH, Pieter
Thanks for the quick responses,
Is there an easy way to format the date differently? I would like to
express the date as a Month-YR. Like this "File_name - July 06.xls"
-Mark
Tom van Stiphout wrote:
On 20 Jul 2006 20:33:50 -0700, "ninrulz" <ni********@hotmail.com>
wrote:
Check out DoCmd.TransferSpreadsheet. It allows you to specify a
filename.
Dim varQueries As Variant
Dim varQuery As Variant
varQueries = Array("Query_name1 - Month-YR.xls", "Query_name2-
Month-YR.xls", "Query_name3- Month-YR.xls") 'etc.
For Each varQuery In varQueries
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9,
varQuery, varQuery & Format$(Date, "yyyymmdd") & ".xls", True
Next
-Tom.
I have created a database that has over 70 queries and over 40k
records. I used the OutputTo action to export the queries to Excel. I
would like the functionality of adding the date (Month-YY) to each of
the Excel file names as they are exported. It seems that the OutputTo
action only allows for predetermined names or a prompt for each file. I
do not want to type the file names 70+ times and renaming each of the
.xls files afterwards is a pain. Can anyone help me to achieve this
type of output?
Query_name1 - Month-YR.xls
Query_name2- Month-YR.xls
Query_name3- Month-YR.xls
Etc.
I think this formula closely fits my needs:
"MyFileName" & "_" & Format(Date(), "yyyymmdd") * ".xls"
Unfortunately, I know nothing about Visual Basic. If the only method of
achieving my goal is using VB, I could use a few pointers.
Many thanks,
Mark
Nevermind...
I am very pleased with the result "file_name - mmyyyy.xls"
Thanks for your help
ninrulz wrote:
Thanks for the quick responses,
Is there an easy way to format the date differently? I would like to
express the date as a Month-YR. Like this "File_name - July 06.xls"
-Mark
Tom van Stiphout wrote:
On 20 Jul 2006 20:33:50 -0700, "ninrulz" <ni********@hotmail.com>
wrote:
Check out DoCmd.TransferSpreadsheet. It allows you to specify a
filename.
Dim varQueries As Variant
Dim varQuery As Variant
varQueries = Array("Query_name1 - Month-YR.xls", "Query_name2-
Month-YR.xls", "Query_name3- Month-YR.xls") 'etc.
For Each varQuery In varQueries
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9,
varQuery, varQuery & Format$(Date, "yyyymmdd") & ".xls", True
Next
-Tom.
>I have created a database that has over 70 queries and over 40k
>records. I used the OutputTo action to export the queries to Excel. I
>would like the functionality of adding the date (Month-YY) to each of
>the Excel file names as they are exported. It seems that the OutputTo
>action only allows for predetermined names or a prompt for each file. I
>do not want to type the file names 70+ times and renaming each of the
>.xls files afterwards is a pain. Can anyone help me to achieve this
>type of output?
>
>Query_name1 - Month-YR.xls
>Query_name2- Month-YR.xls
>Query_name3- Month-YR.xls
>Etc.
>
>I think this formula closely fits my needs:
>
>"MyFileName" & "_" & Format(Date(), "yyyymmdd") * ".xls"
>
>Unfortunately, I know nothing about Visual Basic. If the only method of
>achieving my goal is using VB, I could use a few pointers.
>
>Many thanks,
>Mark
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: ToysNTreasures |
last post by:
Hi,
I'm working on a class project in which I have to create a simple hotel
reservation database using Access. I've created a couple of tables and
queries that allow a user to determine room...
|
by: James P. |
last post by:
Hello there,
In my asp.net page using VB, I have a date text field in mm/dd/yyyy
format. When a date is entered, I'd like to validate it to make sure
the date is greater than or equal to the...
|
by: vijayk |
last post by:
Hi all,
I have a field which has data as YYYYMMDD, and I have to find the age
of the person by substracting it from current date. can you please
please advice...
thanks
|
by: markryde |
last post by:
Hello,
I am trying to add the current date to a file name in python script
like thus:
import os
import sys
import rpm
import time
import datetime
|
by: Shawger Lager |
last post by:
Hi, I am new to DB2 (and SQL) and I am having some problems with the current date. I am trying to make sure the date in the table review is not past the current day using a constriant. I have tried...
|
by: shiznaw |
last post by:
Private Function rprtdate()
Dim rprtdates As Date
Dim 1mnth As Integer
1mnth= Month(Date) + Month(DateSerial(Year(Date), Month(Date) + 1, Day(Date)))
Select Case Frame35.Value
'the following...
|
by: bruce24444 |
last post by:
I have a database which assigns warranty claims to people with a main screen showing number of files assigned to each person. The number assigned shows day, week, month and year numbers so they can...
|
by: nagarwal |
last post by:
Hi All,
I am having prblm in adding the no. of days passed to the current date, in a class fuction.
This is an immediate requirment plz help..
I am using java.util.Date object for the current...
|
by: debasisdas |
last post by:
This article consistes of some of the frequently asked date related queries.
Hope the users find it useful.
==========================
1.Determining the Date of the First and Last Occurrence of a...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |