FoeHunter
Board Regular
- Joined
- Nov 12, 2008
- Messages
- 236
The following code works in two of the following conditions, but not for the 3rd. How can it be re-written to work for all 3?
Condition1 - Directory does not exist at all (the code works)
Condition2 - Directory does exist, but there is no excel file (the code does not work)
Condition3 - Directory does exist, and the excel file is already present (the code works)
As always, thanks in advance
Condition1 - Directory does not exist at all (the code works)
Condition2 - Directory does exist, but there is no excel file (the code does not work)
Condition3 - Directory does exist, and the excel file is already present (the code works)
As always, thanks in advance
Code:
'Defines variables
Dim rs As DAO.Recordset
Dim FPath As String
Dim FName As String
Set rs = CurrentDb.OpenRecordset("SELECT t.[File Location], t.[File Name] FROM [ExportInformation] t", dbOpenDynaset)
' Pulls info from table
FPath = rs.Fields("File Location").Value
FName = rs.Fields("File Name").Value
'Verifies to see if export directory exists. If it does not already exist, it is created.
If Dir(FPath & "\") = "" Then
MkDir (FPath)
Else
'do nothing for the "C:\Junk" directory already exists
End If
' Error handeling routine
On Error GoTo Errorhand
' Exports the database to an excel file
DoCmd.TransferSpreadsheet acExport, 10, "MasterTable", FPath & "\" & FName, True, , False
If ErrorCount > 0 Then GoTo Errorhand2 Else GoTo Errorhand3
Errorhand:
ErrorCount = ErrorCount + 1
Resume Next
Errorhand2:
MsgBox ("Custom export was not complete."), vbCritical, "//// ERROR ////"
GoTo FinalEnd
Errorhand3:
MsgBox ("Successfully exported to " & FPath & "\" & FName), vbInformation, "!!!! SUCCESS !!!!"
GoTo FinalEnd
FinalEnd: