Hi there,
I have a MS-Access form displaying a list of patient and procedures performed on them. I've been asked to add an "Export to Excel" button, so our users can export the data, reorganize and filter it anyway they want.
The way I'm doing it is:
a) get a reference to the form;
b) copy the form's recordset in a DAO.Recordset object;
c) instantiate an Excel.Application object;
d) loop a first time on the Recorset.Fileds property to get the headings names;
e) Copy the recordSet to the declared Range
f) Manage the filename to save, formatting, etc. and clean-up
Problem is; it'll go smoothly on the firstrun, exporting the data, saving my file, formatting and closing everything, but if I try it another time, it'll only produce an empty spreadsheet, with the header line, but no records.
Looking at it in debug shows there the correct number of re3cords in the recordset object, but they wont appear in my worksheet 'till the Access form have been closed and reopened, or refreshed...
Any idea why that is?
I have a MS-Access form displaying a list of patient and procedures performed on them. I've been asked to add an "Export to Excel" button, so our users can export the data, reorganize and filter it anyway they want.
The way I'm doing it is:
a) get a reference to the form;
Code:
Dim frm As Form, destRecSet As DAO.Recordset, intCount As Integer, denom As Boolean
Dim ws As Excel.Worksheet, mobjXL As Excel.Application, cheminFichier As String
Set db = CurrentDb
Set frm = Forms("PROCEDURE - liste procedure")
Code:
Set destRecSet = frm.RecordsetClone
Code:
Set mobjXL = New Excel.Application
With mobjXL
.ScreenUpdating = False
.Visible = False
.Workbooks.Add
.DisplayAlerts = True
Code:
For intCount = 0 To destRecSet.Fields.Count - 1
.Cells(1, intCount + 1).Value = destRecSet.Fields(intCount).Name
.Cells(1, intCount + 1).Interior.ColorIndex = 15
Next intCount
Code:
.Range("A2").CopyFromRecordset destRecSet
.ScreenUpdating = True
End With
Code:
mobjXL.Quit
Set frm = Nothing
Set mobjXL = Nothing
destRecSet.Close
Set destRecSet = Nothing
Set ws = Nothing
cheminFichier = ""
Set ra = Nothing
End Sub
Problem is; it'll go smoothly on the firstrun, exporting the data, saving my file, formatting and closing everything, but if I try it another time, it'll only produce an empty spreadsheet, with the header line, but no records.
Looking at it in debug shows there the correct number of re3cords in the recordset object, but they wont appear in my worksheet 'till the Access form have been closed and reopened, or refreshed...
Any idea why that is?