Esporta Query in Excel
Function EsportaExcel()
Dim myPath As String
Dim myFile As String
myPath = Application.CurrentProject.Path
myFile = myPath & "\nomefile.xlsx"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "myQuery", myFile, , "mySheet"
End Function
Public Sub esporta_excel()
On Error GoTo Err
Dim myPath As String
Dim myFile As String
myPath = Application.CurrentProject.Path
Dim myArr As Variant
Dim myElement As String
Dim myIndex As Integer
Dim myDimension As Integer
myArr = Array("Value1", "Value2", [...])
myDimension = UBound(myArr)
myIndex = 0
While myCounter <= myDimension
myElement = myArr(myIndex)
myFile = myPath & "\" & myElement & "_fileName.xlsx"
Forms!myForm!someField.Value = myElement
Forms!myForm.Refresh
Forms!myForm!someField.SetFocus
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "queryName", myFile, , "sheetName"
myIndex = myIndex + 1
Wend
MsgBox "Ok!"
Exit Sub
Err:
MsgBox Err.Description
Exit Sub
End Sub