I need a way to export selected records in a Form to Excel. I found some code that I think will help me do this but I do not know how to attach it to a button. Here is the code:
Public Function ExportToExcel(frmParent As Form, frmSubForm As Form)
Dim rs As Recordset
Dim intCount As Integer
' Create the Excel object
Set mobjXl = New Excel.Application
' Fetch the recordset
Set rs = frmParent.Form.Controls("frmSubForm.[Browse All Issues]").Form.RecordsetClone
With mobjXl
' Add a workbook and turn of Excel updates
.ScreenUpdating = True
.Visible = False
.Workbooks.Add
.DisplayAlerts = True
' Add the column headers
For intCount = 0 To rs.Fields.Count - 1
.Cells(1, intCount + 1).Value = rs.Fields(intCount).Name
Next intCount
' Dump the recordset to Excel
.Range("A2").CopyFromRecordset rs
.Visible = True
End With
End Function
I am fiarly new to access so any help on how to do this best would be much appreciated.