recordset problem (1 Viewer)

John Sh

Member
Local time
Tomorrow, 01:32
Joined
Feb 8, 2021
Messages
410
I have a fairly standard recordset that gives a compile error.
No matter how I word the "if" statement I get "Method or data member not found"
I have tried 'rs.fieldname, rs.fields("fieldname"), rs![fieldname]. I have tried all with a "." or a "!" and keep getting the same error.
I have triple checked the spelling of each and every element in the code but continue to get this compile error.
I have also tried dbopensnapshot.
The highlighted section is either ".fields" in "rs.Fields("Infrafamily")"
or ".Infrafamily" in "rs.Infrafamily"
What am I doing wrong??

Code:
Public Function LastBox()
    Dim rs As Recordset
    Dim iVar As String
    Dim num As Integer
    Dim frm As Form
    num = 0
    iVar = "Malvaceae"
    Set rs = CurrentDb.OpenRecordset("main", dbOpenDynaset)   'dbopensnapshot
    rs.MoveFirst
    Do
        If rs.Fields("Infrafamily") = iVar Or rs.Family = iVar Then
            num = IIf(rs.BoxNo > num, rs.BoxNo, num)
        End If
        rs.MoveNext
    Loop While Not rs.EOF
    LastBox = num
End Function
 

canyonraven

New member
Local time
Today, 10:32
Joined
Jan 30, 2021
Messages
11
Just at a glance, I would say use more (...)s to control the conditional statement and dissect it with comments to localize the problem.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:32
Joined
May 7, 2009
Messages
19,245
maybe you are on the wrong Table?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 10:32
Joined
Feb 28, 2001
Messages
27,191
Try

Code:
If ( rs![Infrafamily] = iVar ) Or ( rs![Family] = iVar ) Then
 

Users who are viewing this thread

Top Bottom