Exporting to Excel

jsic1210

Registered User.
Local time
Today, 07:07
Joined
Feb 29, 2012
Messages
188
Hello,
I'm using VBA to create a query, then export that query, using TransferSpreadsheet, to Excel. Sometimes it works, but sometimes I get an error that the "Object or database is read-only."
The file is NOT read-only, and it's also not open when I do it. I even have a command that if it's open, to give an error message. Here is a chunk of my code:
Code:
'Set variables
strLoc = "E:\MIS\Revenue Targets\"
strFile = strLoc & "Compare Template.xls"


'Create queries
db.CreateQueryDef "YB_Diff", qYB
db.CreateQueryDef "Index_Diff", qIndex

'Export
ExportQuery:
If FileLocked(strFile) Then
    MsgBox "File is currently open."
    GoTo Function_Exit
End If
    'YB
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "YB_Diff", strFile, True
    'Index
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Index_Diff", strFile, True
 

Users who are viewing this thread

Back
Top Bottom