G
GLT
Hi,
I am importing .txt files into records into my database.
All works fine, except at the end of the import it displays a 76 path not
found error. I think it may be looping one too many times but I am not sure.
The code I am using is as follows:
Sub sImportAll()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb()
Set rst = CurrentDb.OpenRecordset("tbl_LogFileDetails")
On Error GoTo E_Handle
Dim strImport As String
Dim lngChars As Long
Dim intFile As Integer
Dim MyFile As String
Dim Fname As String
Dim Counter As Long
'Create a dynamic array variable, and then declare its initial size
Dim DirectoryListArray() As String
ReDim DirectoryListArray(1000)
intFile = FreeFile
'Loop through all the files in the directory by using Dir$ function
MyFile = Dir$("c:\backupdb\*.*")
Do While MyFile <> ""
DirectoryListArray(Counter) = MyFile
MyFile = Dir$
Fname = "C:\backupDB\" & MyFile
'MsgBox MyFile
Open Fname For Input As intFile
lngChars = LOF(intFile)
strImport = Input(lngChars, intFile)
With rst
.AddNew
rst!LogDetails = strImport
.Update
End With
Counter = Counter + 1
intFile = FreeFile
Loop
sExit:
On Error Resume Next
Reset
Exit Sub
E_Handle:
MsgBox Err.Description, vbOKOnly + vbCritical, "Error: " & Err.Number
Resume sExit
End Sub
Can anyone advise what is going wrong?
Cheers,
GLT
I am importing .txt files into records into my database.
All works fine, except at the end of the import it displays a 76 path not
found error. I think it may be looping one too many times but I am not sure.
The code I am using is as follows:
Sub sImportAll()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb()
Set rst = CurrentDb.OpenRecordset("tbl_LogFileDetails")
On Error GoTo E_Handle
Dim strImport As String
Dim lngChars As Long
Dim intFile As Integer
Dim MyFile As String
Dim Fname As String
Dim Counter As Long
'Create a dynamic array variable, and then declare its initial size
Dim DirectoryListArray() As String
ReDim DirectoryListArray(1000)
intFile = FreeFile
'Loop through all the files in the directory by using Dir$ function
MyFile = Dir$("c:\backupdb\*.*")
Do While MyFile <> ""
DirectoryListArray(Counter) = MyFile
MyFile = Dir$
Fname = "C:\backupDB\" & MyFile
'MsgBox MyFile
Open Fname For Input As intFile
lngChars = LOF(intFile)
strImport = Input(lngChars, intFile)
With rst
.AddNew
rst!LogDetails = strImport
.Update
End With
Counter = Counter + 1
intFile = FreeFile
Loop
sExit:
On Error Resume Next
Reset
Exit Sub
E_Handle:
MsgBox Err.Description, vbOKOnly + vbCritical, "Error: " & Err.Number
Resume sExit
End Sub
Can anyone advise what is going wrong?
Cheers,
GLT