aziz rasul
04-05-2001, 07:52 AM
The following code does the following
1. appends the contents of a .car file (essentially a .txt file) into "tblCARFiles"
2. places a value for rstCARFiles("DateofImport") = Now and rstCARFiles("NameofCARFile") = strFileName
into the first and last record of the imported records
3 selects the next .car file and repeats the above (item 2 ) for the new imported records
HERE'S THE PROBLEM.
Each successive import is successful until the number of records in "tblCARFiles" comes to about 41 records. After this the new imported records DON'T APPEND TO THE END OF THE TABLE but somewhere in the middle. This upsets item 2 above and the values are placed in the wrong records.
What I want to happen is to append the records at the end of the recordset each time a new file is imported.
Can anyone understand why this is happening.
I know that I can solve the problem by introducing an AutoNumber field. But is there any other solution.
Here's the code.
Public Function Process_CAR_Files()
Dim MyDB As Database
Dim rstCARFiles As Recordset
Dim Count1 As Long, Count2 As Long, intI As Long
Set MyDB = CurrentDb
strImportDir = "h:\collect\"
strFileExtension = "*.car"
'Obtains the name of the CAR file
strFileName = Dir(strImportDir + strFileExtension)
If Len(strFileName) > 0 Then
strFileName = Dir(strImportDir + strFileExtension)
Do
strFileFullPath = strImportDir + strFileName
Set rstCARFiles = MyDB.OpenRecordset("tblCARFiles", dbOpenDynaset)
If rstCARFiles.RecordCount > 0 Then
rstCARFiles.MoveLast
End If
'Counts the number of records in "tblCARFiles"
Count1 = rstCARFiles.RecordCount
rstCARFiles.Close
PROBLEM BEGINS HERE
'Imports and appends the contents of the CAR file into "tblCARFiles"
DoCmd.TransferText acImportFixed, "spc_IE_CARFiles", "tblCARFiles", strFileFullPath
Set rstCARFiles = MyDB.OpenRecordset("tblCARFiles", dbOpenDynaset)
If rstCARFiles.RecordCount > 0 Then
rstCARFiles.MoveLast
End If
Count2 = rstCARFiles.RecordCount
rstCARFiles.AbsolutePosition = Count1
rstCARFiles.Edit
rstCARFiles("DateofImport") = Now
rstCARFiles("NameofCARFile") = strFileName
rstCARFiles.Update
rstCARFiles.AbsolutePosition = Count2 - 1
rstCARFiles.Edit
rstCARFiles("DateofImport") = Now
rstCARFiles("NameofCARFile") = strFileName
rstCARFiles.Update
rstCARFiles.Close
Loop Until Len(strFileName) = 0
Else
MsgBox "No CAR files are available"
Exit Function
End If
Set MyDB = Nothing
End Function
[This message has been edited by aziz rasul (edited 04-05-2001).]
1. appends the contents of a .car file (essentially a .txt file) into "tblCARFiles"
2. places a value for rstCARFiles("DateofImport") = Now and rstCARFiles("NameofCARFile") = strFileName
into the first and last record of the imported records
3 selects the next .car file and repeats the above (item 2 ) for the new imported records
HERE'S THE PROBLEM.
Each successive import is successful until the number of records in "tblCARFiles" comes to about 41 records. After this the new imported records DON'T APPEND TO THE END OF THE TABLE but somewhere in the middle. This upsets item 2 above and the values are placed in the wrong records.
What I want to happen is to append the records at the end of the recordset each time a new file is imported.
Can anyone understand why this is happening.
I know that I can solve the problem by introducing an AutoNumber field. But is there any other solution.
Here's the code.
Public Function Process_CAR_Files()
Dim MyDB As Database
Dim rstCARFiles As Recordset
Dim Count1 As Long, Count2 As Long, intI As Long
Set MyDB = CurrentDb
strImportDir = "h:\collect\"
strFileExtension = "*.car"
'Obtains the name of the CAR file
strFileName = Dir(strImportDir + strFileExtension)
If Len(strFileName) > 0 Then
strFileName = Dir(strImportDir + strFileExtension)
Do
strFileFullPath = strImportDir + strFileName
Set rstCARFiles = MyDB.OpenRecordset("tblCARFiles", dbOpenDynaset)
If rstCARFiles.RecordCount > 0 Then
rstCARFiles.MoveLast
End If
'Counts the number of records in "tblCARFiles"
Count1 = rstCARFiles.RecordCount
rstCARFiles.Close
PROBLEM BEGINS HERE
'Imports and appends the contents of the CAR file into "tblCARFiles"
DoCmd.TransferText acImportFixed, "spc_IE_CARFiles", "tblCARFiles", strFileFullPath
Set rstCARFiles = MyDB.OpenRecordset("tblCARFiles", dbOpenDynaset)
If rstCARFiles.RecordCount > 0 Then
rstCARFiles.MoveLast
End If
Count2 = rstCARFiles.RecordCount
rstCARFiles.AbsolutePosition = Count1
rstCARFiles.Edit
rstCARFiles("DateofImport") = Now
rstCARFiles("NameofCARFile") = strFileName
rstCARFiles.Update
rstCARFiles.AbsolutePosition = Count2 - 1
rstCARFiles.Edit
rstCARFiles("DateofImport") = Now
rstCARFiles("NameofCARFile") = strFileName
rstCARFiles.Update
rstCARFiles.Close
Loop Until Len(strFileName) = 0
Else
MsgBox "No CAR files are available"
Exit Function
End If
Set MyDB = Nothing
End Function
[This message has been edited by aziz rasul (edited 04-05-2001).]