Run time error '3251' - again...

smehnert

Registered User.
Local time
Today, 16:44
Joined
Jun 15, 2005
Messages
13
:rolleyes: This code did work, but not it dosen't, I am in dispear, I have read through the other 3251 errors, but not seem to solve my problem.

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

:D Please help

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:
Just a thought, do you also have the ADO (ActiveX Data Objects) x.x Library checked? Try: Dim dbs As DAO.Database to disambiguate.
 
Smehnert, because you appear to be from a foreign country, I will elaborate on what Rural is saying:

Change: Dim dbs As Database, rstDeliveries As Recordset, rstFileSpec As Recordset
To: Dim dbs As DAO.Database, rstDeliveries As DAO.Recordset, rstFileSpec As DAO.Recordset
 
Last edited:
Many thanks

Just to clarify I am english but write giberish...

I tried stipulating the DAO. library but I got the same error...

Thanks
 
And you're sure you have a primary key on the table?
 
Defenitely...

there is a primary key, however, I have recently changed it from a Number Field to a Text field... do you think this could be it????

Simon
 

Users who are viewing this thread

Back
Top Bottom