ajetrumpet
Banned
- Local time
- Today, 05:49
- Joined
- Jun 22, 2007
- Messages
- 5,638
all,
this is a continuation of this thread of mine: http://www.access-programmers.co.uk/forums/showthread.php?t=182364
i am looking for a way to refresh a txt file after a DOS redirection of text into my text file. here is my function that I run:
in the above code, I am trying to refresh it by opening the streamed file, then closing it right away. the GetCurrentDirectory function populates the text file with the information from DOS, but the PopulateTable function gets the text file info I had before I ran this function. If there was no file existing, it gives me a empty string. Here is the function that doesn't work:
One thing that may be helpful for people looking at this is that when I simply CLICK on the file name in windows explorer, the size of the file changes, which is the change that I'm trying to register in VBA. I can't figure this out! is there any help out there?
this is a continuation of this thread of mine: http://www.access-programmers.co.uk/forums/showthread.php?t=182364
i am looking for a way to refresh a txt file after a DOS redirection of text into my text file. here is my function that I run:
Code:
Function t()
Call GetCurrentDirectory("-r")
Dim fNum As Long
fNum = FreeFile()
Open "c:\test.txt" For Input As #fNum
Close #fNum
Call PopulateTable
End Function
Code:
Function PopulateTable()
On Error Resume Next
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE * FROM FileContents"
Dim fNum As Long
Dim ReadFile() As String
Dim i As Integer
Dim FileString As String
Dim DoubleSpaceLoc As Double
Dim LengthOfFileSize As Double
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("FileContents", dbOpenDynaset)
fNum = FreeFile()
[COLOR="Red"][B]'THIS OPENS THE FILE, BUT GRABS INFORMATION THAT IS NOT CURRENTLY IN THERE![/B][/COLOR]
Open "c:\test.txt" For Input As #fNum
ReadFile = Split(Input$(LOF(fNum), fNum), vbCrLf)
Close #fNum
For i = LBound(ReadFile) To UBound(ReadFile)
Debug.Print ReadFile(i)
rs.AddNew
rs!filenamefield = Right(ReadFile(i), Len(ReadFile(i)) - InStrRev(ReadFile(i), " "))
'GET THE EXTRACTION VARIABLES IN THIS SECTION
FileString = ReadFile(i)
DoubleSpaceLoc = InStrRev(ReadFile(i), " ")
LengthOfFileSize = (InStr((InStrRev(ReadFile(i), " ") + 2), ReadFile(i), " ")) - _
(InStrRev(ReadFile(i), " ") + 2)
[COLOR="Red"][B]'THIS SECTION POPULATES THE TABLE WITH THE WRONG INFORMATION[/B][/COLOR]
If InStr(ReadFile(i), "<DIR>") = 0 Then
rs!filesizefield = Mid(FileString, (DoubleSpaceLoc + 2), LengthOfFileSize)
Else
rs!filesizefield = "n/a"
End If
If InStr(ReadFile(i), "<DIR>") > 0 Then
rs!filenamefield = Mid(FileString, (DoubleSpaceLoc + 2), (Len(FileString)) - (DoubleSpaceLoc + 1))
Else
rs!filenamefield = Mid(FileString, _
(DoubleSpaceLoc + 2) + (LengthOfFileSize + 1), _
(Len(FileString)) - ((DoubleSpaceLoc + 1) + (LengthOfFileSize - 1)))
End If
rs!full = ReadFile(i)
rs.Update
Next i
DoCmd.SetWarnings True
End Function