Button to run query and paste results in Excel

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to create a button that will run a query and then paste the
results in Excel? I would like to have it so that the results are placed
into a new excel workbork and not saved with a title, because i want the user
to be able to save and name the file whatever they choose. I would
appreciate any help anyone can give me. Thanks in advance.
 
Is it possible to create a button that will run a query and then paste the
results in Excel? I would like to have it so that the results are placed
into a new excel workbork and not saved with a title, because i want the user
to be able to save and name the file whatever they choose. I would
appreciate any help anyone can give me. Thanks in advance.

Look up both the TransferSpreadsheet and the OutputTo methods in VBA
help. Pick the one you like best.
Here is an example of OutputTo:

Public Sub NewExport()

Dim strName As String
strName = InputBox("Name the spreadsheet here")
If Right(strName,4) = ".xls" Then
Else
strName = strName & ".xls"
End If
DoCmd.OutputTo acOutputQuery, "QueryNameHere", acFormatXLS, strName,
True

End Sub

The spreadsheet is saved in the user's MyDocuments folder (unless you
include a different path in the strName), i.e.
c:\MyFolder\SpreadsheetName.xls
 
Back
Top