-
Well I should have done it this way in the first place, sorry it has taken me so long to get here.
But working from the beginning I have gone through step by step.
This code which includes some of yours and some of mine does the basics, it tests if the list file is in the array, if it is it appends the data to the file found in the folder, if it isn't it copies the file to the folder where the array files are.
Now I am not sure this does what you want in terms of finding the Actual Master files.
You seem to know which ones they are, but I don't, if it was me I would place the known master file's paths in a table in the database and refer to them in that way, because takes away the uncertainty of whether it is the correct file.
It doesn't include the part of your code that renames the file to temp for copying as I am not sure of the logic behind it.
But at least I have got it this far, the rest should just be finessing what we have to include your equirements.
Here is the code, as usual you do not the message boxes which are there to show the progress through the code.
Dim CheckFile, FileFound As String, AllOk As Boolean, i As Integer, ErrMsg As String, sOrigin As String, datastring As String
Dim sDest As String, strFileTemp As String, FileExist As String, filed As Date, firstfile As String, firstfiled As Date
Dim ctlList As Control, varItem As Integer, posn As Integer, FileName As String, result As Integer, fileinarray As Integer
CheckFile = Array("TESTMAIN", "TESTCASE", "TESTPRIMARY", "TESTSECONDARY", "TESTALTERNATE")
On Error GoTo errorcatch
Set fs = CreateObject("Scripting.FileSystemObject")
'The following lines of code use a network path for the source file :
sDest = "C:\Users\A C\Downloads\TestFolder\" ' & CheckFile(0) ' will be changed to CurrentProject.path & MAXIMOExports
sOrigin = "C:\Users\A C\Downloads\TestFolder2\"
'MsgBox sDest & " " & sOrigin
Set ctlList = Me.List0
For varItem = 0 To ctlList.ListCount - 1
For x = 1 To Len(ctlList.ItemData(varItem))
' Parse filename only
If Mid(ctlList.ItemData(varItem), x, 1) = "\" Then posn = x
Next x
firstfile = ctlList.ItemData(varItem)
FileName = Right(ctlList.ItemData(varItem), Len(ctlList.ItemData(varItem)) - posn)
'MsgBox varItem & " - " & FileName
result = 0
fileinarray = 0
For i = LBound(CheckFile) To UBound(CheckFile)
result = InStr(1, ctlList.ItemData(varItem), CheckFile(i))
'MsgBox ctlList.ItemData(varItem) & " - " & CheckFile(i)
If result <> 0 Then
MsgBox result & " - File is in array append it"
fileinarray = 1
FileFound = Dir(sDest & CheckFile(i) & "*.*")
MsgBox FileFound
Open sDest & FileFound For Append As #2
MsgBox firstfile
'Open sSourceFile For Input As SourceFileNum
Open firstfile For Input As #1
MsgBox 2
Do Until EOF(1)
Line Input #1, datastring
MsgBox datastring
Print #2, datastring
Loop
Close #2
Close #1
Exit For
End If
Next i
If fileinarray = 0 Then
MsgBox result & " - file is not in array copy it"
FileCopy ctlList.ItemData(varItem), sDest & FileName
End If
Next varItem
Exit Sub
errorcatch:
Close #2
Close #1
MsgBox "Error - " & Err.Description
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules