Solved

Naming an output file

Posted on 2004-10-13
7
993 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

856 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