Good question - I know it works in XP. I don't have a Vista machine here -
I thinks it's c:\users\theirname\documents - I'll have to check. In which
case use ..\documents - you'll have to test this.
There is nothing special about the query - it selects from a table and query
and is created in VBA code (I shortened it for this example).
This creates an unformatted Excel worksheet.
Private Sub cmdImagesListExcel_Click()
On Error GoTo Err_cmdImagesListExcel_Click
Kill "..\Desktop\ImagesList.xls" 'Deletes previous copy on the
desktop
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim strDateSQL As String
Set dbs = CurrentDb
strDateSQL = "SELECT [FileName] & '.tif' AS FILENAME_TIF,
qryImagesinList2.BaseDocNumber AS [DWG No], " & _
"qryImagesinList2.BaseDocType AS [DOC TYPE],
qryImagesinList2.JFrameNumber AS [FRAME No], " & _
"qryImagesinList2.JNumberOfFrames AS [No FRAMES] " & _
"FROM qryImagesinList2, MetaData " & _
"WHERE (((MetaData.FILENAMETIF) = [FileName] & '.tif')) " & _
"ORDER BY [FileName] & '.tif';"
For Each qdf In CurrentDb.QueryDefs 'deletes the query created
previously to avoid an error message
If qdf.Name = "qryImagesListExcel" Then
CurrentDb.QueryDefs.Delete "qryImagesListExcel"
Exit For
End If
Next
Set qdf = dbs.CreateQueryDef("qryImagesListExcel", strDateSQL)
'creates a new query and saves it
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
"qryImagesListExcel", "..\Desktop\ImagesList.xls", True
'send to desktop
MsgBox "'ImagesList.xls' speadsheet created successfully on Desktop"
Exit_cmdImagesListExcel_Click:
Exit Sub
Err_cmdImagesListExcel_Click:
Select Case Err.Number
Case 53 'File not found to delete
Resume Next
Case 3012 'File already exists
DoCmd.SetWarnings True
CurrentDb.QueryDefs.Delete "qryImagesListExcel"
Resume
Case Else
MsgBox Err.Number & " " & Err.Description
Resume Exit_cmdImagesListExcel_Click
End Select
End Sub