help with exporting to excel

associates

Registered User.
Local time
Today, 11:01
Joined
Jan 5, 2006
Messages
94
Hi,

I have a form that has a button to export access report to excel. I've got that button working. It creates an excel file based on the access report. However, i want to do something more. In the form, i also have a listbox showing records filtered by a couple of comboboxes. So what i would like to do is to be able to see the excel file with the records only shown on the listbox, not the entire records in the table. I noticed that with the following code, i can't really put thru the stlinkcriteria.

DoCmd.OutputTo acOutputReport, stDocName

Here is my code looks like;

Private Sub CM_Export2excel_Click()
On Error GoTo Err_CM_Export2excel_Click

Dim stDocName As String
Dim stLinkCriteria As String

nList = Me.mylist.ListCount

For ncount = 0 To nList - 1
stLinkCriteria = "," & Me.mylist.ItemData(ncount) & stLinkCriteria
Next ncount

If Len(stLinkCriteria) > 0 Then
stLinkCriteria = "[student_ID] In (" & Mid(stLinkCriteria, 2) & ")"
End If

stDocName = "CHW Job_Report"
DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
DoCmd.Close acReport, stDocName, acSaveYes
DoCmd.OutputTo acOutputReport, stDocName

From the code above, i was trying to create a report with the records from the listbox and save it, then export it to excel and it doesn't work. So i was wondering what would be the better way of doing this.

Thank you in advance
 

Users who are viewing this thread

Back
Top Bottom