The program loops through the listbox and checks if one of the selected files already exist in the directory to which it is being copied. But it seems like it is setting the FileExist flag true if the text string has a match in the listbox and not the destination directory. It should only set FileExist true if the string is in the directory. If that part is working, I then try and open the selected file and matching file in the directory for appending. It will not run past that point because checkfile(i) is an array and not the actual file. Do I need to go back and use MID to retrieve the entire filename so I can actually open the file for appending? I've tried several methods already. Maybe my way of doing this is the wrong way to go about it. Maybe there is a better way to search for existing files and then proceed to the append routine. Any help or advice is welcome. Thanks
Dim CheckFile, FileFound As String, AllOk As Boolean, i As Integer, ErrMsg As String
Dim sDest As String, strFileTemp As String, FileExist As String
Dim ctlList As Control, varItem As Variant, posn As Integer, FileName As String
CheckFile = Array("*TESTMAIN*", "*TESTCASE*", "*TESTPRIMARY*", "*TESTSECONDARY*", "*TESTALTERNATE*")
'The following lines of code use a network path for the source file :
sDest = CurrentProject.path & "\Test Folder\" ' will be changed to CurrentProject.path & MAXIMOExports
' Return Control object variable pointing to Me.FileList list box.
Set ctlList = Me.FileList
' Enumerate through selected items.
For varItem = 0 To ctlList.ListCount - 1
' Print value of bound column - used for testing purposes.
'MsgBox ctlList.ItemData(varItem)
For x = 1 To Len(ctlList.ItemData(varItem))
' Parse filename only
If Mid(ctlList.ItemData(varItem), x, 1) = "\" Then posn = x
Next x
FileName = Right(ctlList.ItemData(varItem), Len(ctlList.ItemData(varItem)) - posn)
' Print value of bound column - used for testing purposes.
MsgBox FileName, vbInformation, "For Testing"
' Replace the extension with _Temp.txt for a temp file
strFileTemp = Replace(ctlList.ItemData(varItem), ".dat", "_Temp.txt")
AllOk = True
For i = LBound(CheckFile) To UBound(CheckFile)
FileFound = Dir(MyPath & "\" & CheckFile(i))
If FileFound = "" Then
FileExist = CheckFile(i)
MsgBox FileExist
AllOk = False
End If
If strFileTemp Like FileExist Then
Open strFileTemp For Input As #1
'Open FileExist For Output As #8
'Do Until EOF(1)
'xchar = Input(1, #1)
'MsgBox xchar
FileExist = True '- used in testing
MsgBox FileExist '- used in testing
End If
'ErrMsg = ErrMsg & CheckFile(i) & vbNewLine
Next i
If Not AllOk Then
'MsgBox strFileTemp, vbInformation, "FileExist"
' Copy .txt files
FileCopy ctlList.ItemData(varItem), sDest & strFileTemp
' Reset file extension .dat
FileName = Right(ctlList.ItemData(varItem), Len(ctlList.ItemData(varItem)) - posn)
' Copy dat file
FileCopy ctlList.ItemData(varItem), sDest & FileName
End If
Next varItem
' Print file storage location
MsgBox CurrentProject.path & "\Test Folder\", vbInformation, "Files Have Been Copied To The Below Location:"
'Kill strFileTemp
' Check that all files in Me.FileList copied MaximoExports directory
If Dir(CurrentProject.path & "\Test Folder\") = FileName Then
MsgBox "All files were successfully imported"
Else
MsgBox "All Files Did Not Import. Return To Import Menu"
End If