[AccessD] Code to Copy a query to Excel and Open said file?

E-business2start.com - Marcel Vreuls oost at e-business2start.com
Mon Mar 6 10:13:52 CST 2006


Hi Ervin,
Do not now if your already solved the problem. I use the function underneed. The clsprogress class is my progress bar but you can delete it or use a own one.
If you do not have the sql string you can use the name propertie of the query to get the sql statement <query>.name
Regards marcel
 
Public Function fncExportNaarExcel(strSQL As String) On Error Resume Next 'ivm het eventueel niet aanwezig zijn van de exporteren query

If strSQL = "" Or IsNull(strSQL) Then
MsgBox "Er kunnen geen gegevens gevonden worden", vbInformation, pMsgboxHeader
Exit Function
Else

Dim objProgress As New clsProgress
Dim daodatabase As DAO.database
Set daodatabase = CurrentDb()

objProgress.ShowProgress
objProgress.TextMsg = "Verzamelen van de gegevens..."

daodatabase.QueryDefs.Delete ("Exporteren")

objProgress.TextMsg= "Exporteren van de gegevens..."

daodatabase.CreateQueryDef "Exporteren", strSQL

objProgress.TextMsg = "Starten van Microsoft Excel..."

DoCmd.OutputTo acOutputQuery, "Exporteren", acFormatXLS, "c:\export.xls", True

objProgress.HideProgress

Set objProgress = Nothing
End If

Exit Function
 
Exit_Ooperror:
Exit Function
Ooperror:
Call lci_ErrMsgStd(Name, Err.Number, Err.Description, True)
Resume Exit_Ooperror
End Function




More information about the AccessD mailing list