Hi all, could someone please advise me how to send the records returned from a query to a specific sheet in an excel spreadsheet using VBA if possible.
The bit of code below will create all the sheets i need, but it's missing the code to paste the query result to selected sheet. I hope i've explained it clearly. Any help appreciated. thanks
Set db = CurrentDb
' All distinct supplier names in this query
Set qd = db.QueryDefs("Distinct_Supplier") For Each Param In
qd.Parameters
Param.Value = Eval(Param.Name)
Next Param
DoCmd.SetWarnings True
Set rs = qd.OpenRecordset()
While Not rs.EOF And Not rs.BOF
'*************************************************
Me.sup = rs!SupplierName
'************************
DoEvents
xlapp.Visible = False
xlapp.Workbooks.Open (ExportDir & ExportFile)
xlapp.DisplayAlerts = False
On Error Resume Next
DoCmd.SetWarnings False
xlapp.Sheets.Add.Name = sup 'Adds the sheets to spreadsheet
****************************
Missing code to select sheet and paste query result goes here?
****************************
xlapp.SaveWorkspace
xlapp.Workbooks.Close
xlapp.Application.Quit
Set xlapp = Nothing
rs.MoveNext
Wend
The bit of code below will create all the sheets i need, but it's missing the code to paste the query result to selected sheet. I hope i've explained it clearly. Any help appreciated. thanks
Set db = CurrentDb
' All distinct supplier names in this query
Set qd = db.QueryDefs("Distinct_Supplier") For Each Param In
qd.Parameters
Param.Value = Eval(Param.Name)
Next Param
DoCmd.SetWarnings True
Set rs = qd.OpenRecordset()
While Not rs.EOF And Not rs.BOF
'*************************************************
Me.sup = rs!SupplierName
'************************
DoEvents
xlapp.Visible = False
xlapp.Workbooks.Open (ExportDir & ExportFile)
xlapp.DisplayAlerts = False
On Error Resume Next
DoCmd.SetWarnings False
xlapp.Sheets.Add.Name = sup 'Adds the sheets to spreadsheet
****************************
Missing code to select sheet and paste query result goes here?
****************************
xlapp.SaveWorkspace
xlapp.Workbooks.Close
xlapp.Application.Quit
Set xlapp = Nothing
rs.MoveNext
Wend