|
|
Question : Naming an output file
|
|
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
|
Answer : Naming an output file
|
|
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 :))
|
|
|
|
|