
I am now getting operation not supported for this type of object...
when I debug its this line it doesn't like: rstDeliveries.Index = "PrimaryKey"
I have checked my references and are using M.. DAO 3.6 Library

The full code is thus...
Code:
Public Function ImportInfo() As String
Dim dbs As Database, rstDeliveries As Recordset, rstFileSpec As Recordset
Dim NumRec As Long
Dim MyString As String, NumFields As Integer, i As Integer, n As Integer
' ***Return reference to current database
Set dbs = CurrentDb
'***open the text file
Open getpath(dbs.Name) & "quality.txt" For Input As #1
' ***Create a dynaset-type Recordset object based on Shoes table.
Set rstDeliveries = dbs.OpenRecordset("tblDeliveries")
'*******THIS LINE IS THE ONLY DIFFERENCE *********
Set rstFileSpec = dbs.OpenRecordset("tblxSpec")
'*************************************************
NumFields = rstFileSpec.RecordCount
Dim ImportString() As Variant
ReDim ImportString(NumFields)
' ***Set index for SEEK
rstDeliveries.Index = "PrimaryKey"
NumRec = 1
' ***Open the text file
Do While Not EOF(1)
' ***Read a line of text
For n = 1 To 11
Line Input #1, MyString
Next n
rstFileSpec.MoveFirst
' ***Parse the string into variant array
For i = 1 To NumFields
ImportString(i) = Mid(MyString, rstFileSpec!start, rstFileSpec!Width)
' *** Strip out the - of the customer ref no
'If i = 1 Then
'ImportString(i) = Trim(ImportString(i))
'ImportString(i) = Mid(ImportString(i), 1, 3) & Mid(ImportString(i), 5, 2) & Mid(ImportString(i), 8, 1)
'End If
rstFileSpec.MoveNext
Next i
rstDeliveries.Seek "=", ImportString(1)
If rstDeliveries.NoMatch Then
'***Add a new Record
rstDeliveries.AddNew
rstFileSpec.MoveFirst
For i = 1 To NumFields
rstDeliveries(rstFileSpec!FieldName) = ImportString(i)
rstFileSpec.MoveNext
Next i
rstDeliveries.Update
NumRec = NumRec + 1
Else
'***Update Record
rstDeliveries.Edit
rstFileSpec.MoveFirst
For i = 1 To NumFields
rstDeliveries(rstFileSpec!FieldName) = ImportString(i)
rstFileSpec.MoveNext
Next i
rstDeliveries.Update
NumRec = NumRec + 1
End If
Loop
' ***Close text file.
Close #1
'***rstImport.Close
rstDeliveries.Close
Set rstDeliveries = Nothing
rstFileSpec.Close
Set rstFileSpec = Nothing
Set dbs = Nothing
MsgBox NumRec - 1 & " Records Processed"
End Function
Last edited by a moderator: