Solved

Naming an output file

Posted on 2004-10-13
7
988 Views
Last Modified: 2007-12-19
I am attempting to output club records from an Access database to an XLS format on a 'per club' basis using a command button and a parameter query.

I can output the single club file with this line:

DoCmd.OutputTo acQuery, "qryRollCall2XLS",
"MicrosoftExcelBiff8*.xls)", "E:\###\Database.xls", True, "", 0

using the parameter query.

I then attempted to make separate XLS files per club with this which is based on code I use to make RTF output from a report.

DoCmd.OutputTo acQuery, "qryRollCall2XLS",
"MicrosoftExcelBiff8 *.xls)", "E:\###\"  "Database_ID" & Me![Club
Ident] & ".xls", True, "", 0

I have not adapted it correctly because the error message reports that it can't find the field [Club Ident].

The next task will be to learn about making the separate XLS files without the need to use the command button 60 times.

Robin Chapple
0
Comment
Question by:robinski
  • 4
7 Comments
 
LVL 5

Expert Comment

by:ZenMasterrr
ID: 12295435
try.....

DoCmd.OutputTo acQuery, "qryRollCall2XLS",
"MicrosoftExcelBiff8 *.xls)", "E:\###\" & "Database_ID" & Me![Club
Ident] & ".xls", True, "", 0
0
 
LVL 5

Accepted Solution

by:
ZenMasterrr earned 250 total points
ID: 12295498
to avoid the command button


create table with your clubs.... tblClubs

Function ExportClubs()

Dim I as Integer
Dim MyDB as Database
Dim MyRec as Recordset

Set MyDB = CurrentDB
Set MyRec = MyDB.OpenRecordset("SELECT DatabaseID, ClubIdent FROM tblClubs",dbopendynaset,dbreadonly)

If MyRec.eof and Myrec.bof then
     I = Msgbox("NoRecords in tblClubs",vbokonly, "Error")
Else
MyRec.MoveFirst

For I = 0 to MyRec.recordcount -1
       MyDb.QueryDefs("qryRollCall3XLS").SQL = "SELECT * FROM qryRollCall2XLS WHERE ClubID ='" & MyRec!ClubID & "'"
       DoCmd.OutputTo acQuery, "qryRollCall3XLS","MicrosoftExcelBiff8 *.xls)", "E:\###\" & MyRec!DatabaseID & MyRec!ClubId & ".xls", True, "", 0
       MyRec.movenext
End
End If
MyRec.close
MyDb.close
Set MyRec = Nothing
Set MyDB = Nothing

End Function


Zen :))


0
 
LVL 5

Expert Comment

by:ZenMasterrr
ID: 12295500
..oh you need to create another query......qryRollCall3XLS
0
 
LVL 5

Expert Comment

by:ZenMasterrr
ID: 12295508
If MyRec.eof and Myrec.bof then
     I = Msgbox("NoRecords in tblClubs",vbokonly, "Error")
Else
MyRec.MoveFirst

For I = 0 to MyRec.recordcount -1
       MyDb.QueryDefs("qryRollCall3XLS").SQL = "SELECT * FROM qryRollCall2XLS WHERE ClubID ='" & MyRec!ClubID & "'"
       DoCmd.OutputTo acQuery, "qryRollCall3XLS","MicrosoftExcelBiff8 *.xls)", "E:\###\" & MyRec!DatabaseID & MyRec!ClubId & ".xls", True, "", 0
       MyRec.movenext
Loop
End If

hehe...having a blonde day
0
 

Author Comment

by:robinski
ID: 12301150
Zenmasterrr

Thanks for your help.

I am testing Item One first;

I notice a closing ) without an opening (

and in all the other pieces of code.

Is that confirmed?

Please also confirm that subsequent code is designed to produce the 60 files, in which case the points will be revised to 500 because I intended a separate question for that.

Robin
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now