Avatar of VGuerra67
VGuerra67
 asked on

need to get the last record of a table

I have a client table where i assign client numbers.  I would like to go to the last record and add one to the client numbers.  
This is my code.

 Set db = CurrentDb
        Set rs = db.OpenRecordset("SELECT RIGACCT FROM ClientInfo")
        rs.MoveLast
        'rs.Move -1
        'Debug.Print rs("rigacct")
        BacctNum = rs!RIGAcct
        AcctNum = BacctNum + 1
        Me.RIGAcct = AcctNum
        'Me.Requery

It stopped working for me. it gets stuck on the Set rs.  The error message that i get is in valid type.

Any help would be appreciated
Microsoft Access

Avatar of undefined
Last Comment
Remya 6488

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Fabrice Lambert

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
VGuerra67

ASKER
thank you
Remya 6488

HI,

I think instead of iteratiing the resultset till the end, you can use a simple  query like
    SELECT TOP 1 RIGACCT + 1 FROM ClientInfo ORDER BY ID DESC
   where, Id is the unique auto generating column of the table
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck