GohDiamond
"Access- Imagineer that!"
- Local time
- Today, 15:48
- Joined
- Nov 1, 2006
- Messages
- 550
Hello again,
I'm using the 'docmd.output to' action to output excel files to a specific directory on my computer. The output works fine except, it DOESN'T recognize existing files of the same name and type <filename.xls> for example and ask if you want to overwrite the file.
I want to have that safeguard in the function. Here is the code.
'******************** Code Begin ****************
'This part gets the base path automagically
'
'Code courtesy of
'Terry Kreft & Ken Getz
'
Function CurrentDBDir() As String
Dim strDBPath As String
Dim strDBFile As String
strDBPath = CurrentDb.Name
strDBFile = Dir(strDBPath)
CurrentDBDir = Left$(strDBPath, Len(strDBPath) - Len(strDBFile))
End Function
'******************** Code End ****************
'------------------------------------------------------------
' Export_Corporate - Exports a query called Corporate to an Excel.xls file to the directory indicated (Exports\Corporate\Corporate.xls)
'
'------------------------------------------------------------
Function Export_Corporate()
On Error GoTo Export_Corporate_Err
DoCmd.OutputTo acOutputQuery, "Corporate", "Excel97-Excel2003Workbook(*.xls)", CurrentDBDir & "Exports\Corporate\Corporate.xls", False, "", 0, acExportQualityPrint
Export_Corporate_Exit:
Exit Function
Export_Corporate_Err:
MsgBox Error$
Resume Export_Corporate_Exit
End Function
------------------------------------------------
How can I get it to ask about OVERWRITING the existing file if it's there?
Cheers!
GohDiamond
I'm using the 'docmd.output to' action to output excel files to a specific directory on my computer. The output works fine except, it DOESN'T recognize existing files of the same name and type <filename.xls> for example and ask if you want to overwrite the file.
I want to have that safeguard in the function. Here is the code.
'******************** Code Begin ****************
'This part gets the base path automagically

'
'Code courtesy of
'Terry Kreft & Ken Getz
'
Function CurrentDBDir() As String
Dim strDBPath As String
Dim strDBFile As String
strDBPath = CurrentDb.Name
strDBFile = Dir(strDBPath)
CurrentDBDir = Left$(strDBPath, Len(strDBPath) - Len(strDBFile))
End Function
'******************** Code End ****************
'------------------------------------------------------------
' Export_Corporate - Exports a query called Corporate to an Excel.xls file to the directory indicated (Exports\Corporate\Corporate.xls)
'
'------------------------------------------------------------
Function Export_Corporate()
On Error GoTo Export_Corporate_Err
DoCmd.OutputTo acOutputQuery, "Corporate", "Excel97-Excel2003Workbook(*.xls)", CurrentDBDir & "Exports\Corporate\Corporate.xls", False, "", 0, acExportQualityPrint
Export_Corporate_Exit:
Exit Function
Export_Corporate_Err:
MsgBox Error$
Resume Export_Corporate_Exit
End Function
------------------------------------------------

Cheers!
GohDiamond