Thanks for your input guys.
Fornation
U r right in what u said. However u can't prevent someone from going into to table direct.
Pat
I understood what u said. The problem is that I have no control over the table in question. Placing an autonumber field would solve the problem as u said. However if I can't place an autonumber, what happens then? In short it doesn't work. Hence the reason why I'm trying to find a VBA way of forcing the sort sequence before appending.
Note that when the data is imported, some data is written in 3 fields in the first and last records of the import. Since the sort sequence can potentially change, the written data goes to the wrong records in the table when I use the AbsolutePosition property of a recordset.
Here's part of the code which will help to understand what the problem.
Public Function Process_CAR_Files()
Dim MyDB As Database
Dim rstCARFiles As Recordset
Dim Count1 As Long, Count2 As Long
Dim DateStamp As Date
Set MyDB = CurrentDb
strImportDir = "w:\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
'Extracts the date and time that the CAR file was created
DateStamp = FileDateTime(strFileFullPath)
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
'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("DateofCARFile") = DateStamp
rstCARFiles("DateofImport") = Now
rstCARFiles("NameofCARFile") = strFileName
rstCARFiles.Update
rstCARFiles.AbsolutePosition = Count2 - 1
rstCARFiles.Edit
rstCARFiles("DateofCARFile") = DateStamp
rstCARFiles("DateofImport") = Now
rstCARFiles("NameofCARFile") = strFileName
rstCARFiles.Update
rstCARFiles.Close
Loop Until Len(strFileName) = 0
Else
MsgBox "No CAR files are available"
End If
End Function
[This message has been edited by aziz rasul (edited 04-09-2001).]