kevin_n_pa
New Member
- Joined
- Dec 25, 2017
- Messages
- 3
I wrote a program to input a CSV file, slice and dice the data and output a report. The program prompts the user to select a specific CSV file from the files in a fixed folder. The program then saves the file to C:\temp. The program also saves a copy of a schema.ini file from a separate fixed folder (no user prompt) to the same C-drive folder. The code includes checks to verify the paths of the two source folders and the existence of the schema.ini file.
The program verifies the path to the C-drive folder; no problem. But it doesn't recognize the path to the folder containing the schema.ini file. I've checked and double checked the code and the path names.
I found a solution by using the FolderExists method and Application.FileDialog(msoFileDialogFolderPicker) and looping through the verification. The program recognizes the path the second time. It's not elegant. But it seems to solve the problem.
I would prefer to find the root cause of the problem and correction I can trust. Note: The problem path is located on an Intranet. Not sure if this matters.
Any help would be greatly appreciated. Thank you.
Kevin
The program verifies the path to the C-drive folder; no problem. But it doesn't recognize the path to the folder containing the schema.ini file. I've checked and double checked the code and the path names.
I found a solution by using the FolderExists method and Application.FileDialog(msoFileDialogFolderPicker) and looping through the verification. The program recognizes the path the second time. It's not elegant. But it seems to solve the problem.
I would prefer to find the root cause of the problem and correction I can trust. Note: The problem path is located on an Intranet. Not sure if this matters.
Any help would be greatly appreciated. Thank you.
Kevin
Code:
[COLOR=#333333]Dim FSO As Scripting.FileSystemObject[/COLOR]
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">Dim fdl As FileDialog
Dim i As Integer
Set FSO = New Scripting.FileSystemObject
i = 1
Cdrive_2ndCheck:
If i > 2 Then
MsgBox "The path " & """" & CSVDestinationFolder & """" & " cannot be verified." & _
Chr(10) & Chr(10) & _
"The program will be stopped. No report will be created."
GoTo EndProgram
End If
' verify path to CSV file temporary location
If FSO.FolderExists(CSVDestinationFolder & "\") = False Then
Set fdl = Application.FileDialog(msoFileDialogFolderPicker)
fdl.InitialFileName = CSVDestinationFolder & "\"
Set fdl = Nothing
i = i + 1
GoTo Cdrive_2ndCheck
End If
' verify if SCHEMA.INI exists
Application.StatusBar = "Copying schema.ini file to temporary location..."
If VerifyFileExists(CSVDestinationFolder & "\" & SchemaINIfilename) = False Then
i = 1
SchemaINI_2ndCheck:
If i > 2 Then
MsgBox "The path to the location of " & """" & "schema.ini" & """" & " cannot be verified." & _
Chr(10) & Chr(10) & _
"The program will be stopped. No report will be created."
GoTo EndProgram
End If
' verify path to source location of schema.ini
If FSO.FolderExists(SchemaINIpath & "\") = False Then ' path and/or file cannot be verified
Set fdl = Application.FileDialog(msoFileDialogFolderPicker)
fdl.InitialFileName = SchemaINIpath & "\"
Set fdl = Nothing
i = i + 1
GoTo SchemaINI_2ndCheck
Else
' path is verified and file exists in the folder
If VerifyFileExists(CSVDestinationFolder & "\" & SchemaINIfilename) = False Then
FileCopy SchemaINIpath & "\" & SchemaINIfilename, CSVDestinationFolder & "\" & SchemaINIfilename
End If
End If </code>[COLOR=#333333] End If[/COLOR]