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 / Macros / April 2006

Tip: Looking for answers? Try searching our database.

Is there a simple way to create multiple output files from a single query?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gary J. Dikkema - 15 Apr 2006 21:05 GMT
I need the ability to build up to 58 output files from a single query.
There's a field that can be used to control this.

Tough question?
Ken Snell (MVP) - 15 Apr 2006 22:14 GMT
Probably not... but give us more details please.

Signature

       Ken Snell
<MS ACCESS MVP>

>I need the ability to build up to 58 output files from a single query.
>There's a field that can be used to control this.
>
> Tough question?
Gary J. Dikkema - 15 Apr 2006 23:28 GMT
Maybe it's an Excel macro I'm thinking of that allows subsetting into
different work sheets?

Anyways I have a control field with 57 values and I want to build a
worksheet or unique tables based on that.

Actually I want to be able to take the worksheet and attach each to a unique
email account for mailing.

> Probably not... but give us more details please.
>
>>I need the ability to build up to 58 output files from a single query.
>>There's a field that can be used to control this.
>>
>> Tough question?
Ken Snell (MVP) - 16 Apr 2006 01:30 GMT
Can you give us details about the query and the table? Do you want to create
individual EXCEL files, one for each value in the field?

Signature

       Ken Snell
<MS ACCESS MVP>

> Maybe it's an Excel macro I'm thinking of that allows subsetting into
> different work sheets?
[quoted text clipped - 11 lines]
>>>
>>> Tough question?
Gary J. Dikkema - 16 Apr 2006 12:30 GMT
I have a table with some 6 fields, one of the fields contains the city.

There are some 50+ cities.

I want to create a unique table for each of those 50+ cities.

The data has to be exported and each attached to a unique email.

Perhaps it would be better to do this outside of Access....

> Can you give us details about the query and the table? Do you want to
> create individual EXCEL files, one for each value in the field?
[quoted text clipped - 14 lines]
>>>>
>>>> Tough question?
Douglas J. Steele - 16 Apr 2006 14:45 GMT
Why? Having 50+ separate tables, all with the same data, sounds like a
fairly major violation of database normalization principles.

Strikes me that a parameter query that allows you to specify which city you
want is all you need in this case.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)

>I have a table with some 6 fields, one of the fields contains the city.
>
[quoted text clipped - 24 lines]
>>>>>
>>>>> Tough question?
Gary J. Dikkema - 17 Apr 2006 13:41 GMT
Agreed!

However, I need a different output file created for each city.

I ALWAYS need to create a unique file for each city... that would be 57
files in total created....

> Why? Having 50+ separate tables, all with the same data, sounds like a
> fairly major violation of database normalization principles.
[quoted text clipped - 30 lines]
>>>>>>
>>>>>> Tough question?
Douglas J. Steele - 17 Apr 2006 16:55 GMT
That's fine. You need 1 query, and one bit of code.

Assuming you want the files to include the city name as part of the file
name, you'd do something like the following untested air code:

Dim dbCurr As DAO.Database
Dim qdfCurr As DAO.QueryDef
Dim rsCurr As DAO.Recordset
Dim strCity As String
Dim strFile As String
Dim strSQL As String

  Set dbCurr = CurrentDb()
  Set rsCurr = dbCurr.OpenRecordset("SELECT CityNm FROM Cities")
  Do Until rsCurr.EOF = False
     strCity = rsCurr!CityNm
     strFile = "C:\Output Files\" & strCity & ".txt"
     strSQL = "SELECT Field1, Field2, Field3 "  & _
        "FROM MyTable " & _
        "WHERE City = '" & strCity & "'"

     Set qdfCurr = dbCurr.QueryDefs("MyCityQuery")
     qdfCurr.SQL = strSQL

     DoCmd.TransferText acExportDelim, , "MyCItyQuery", strFile

     rsCurr.MoveNext
  Loop

  rsCurr.Close
  Set rsCurr = Nothing
  Set qdfCurr = Nothing
  Set dbCurr = Nothing

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)

> Agreed!
>
[quoted text clipped - 37 lines]
>>>>>>>
>>>>>>> Tough question?
Gary J. Dikkema - 17 Apr 2006 18:35 GMT
THANKS!

> That's fine. You need 1 query, and one bit of code.
>
[quoted text clipped - 71 lines]
>>>>>>>>
>>>>>>>> Tough question?
Gary J. Dikkema - 17 Apr 2006 19:18 GMT
This looks like what I want except I'm not to good with VBA code (and that's
an understatement). <VBG>

So I created a new module and made this a public function and invoke this
from a macro.

I modified the rsCurr statement to point to my file and my field name... as
well as the strSQL...

But nothing happens.

Like I said, VBA is a weak point.

<VBG>

Sorry to ask for what is probably a pretty easy answer...

Thanks again.

> That's fine. You need 1 query, and one bit of code.
>
[quoted text clipped - 71 lines]
>>>>>>>>
>>>>>>>> Tough question?
Rita - 17 Apr 2006 11:46 GMT
I have a similar situation...

in my case...  I need to print individual snapshots for every entry in the
query...

> Can you give us details about the query and the table? Do you want to create
> individual EXCEL files, one for each value in the field?
[quoted text clipped - 14 lines]
> >>>
> >>> Tough question?
 
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.