Link to home
Create AccountLog in
Microsoft Access

Microsoft Access

--

Questions

--

Followers

Top Experts

Avatar of marku24
marku24🇺🇸

Finding MAX value in a recordset in Access VBA
I am trying to pull back a recordset in VBA to determine the highest Event ID in the table so I can increment by 1 to add the next.  The EventID field is numeric.  If I SELECT * instead of MAX(EventID) I do pull back all the records which I can tell by using recordcount.  When I use MAX I only pull back the 1 record, which I expect but I can't get the value that is in Event ID.  It is telling me "Item not found in this collection" but EventID is in the RS.  Here is the code:

strSQL = "Select MAX(EventID) from [tblEvents] where EventStatus = '" & strEventStatusSearch & "'"
        Set rs = db.OpenRecordset(strSQL)
        intMAXeventID = rs!EventID

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)DatabaseMX (Joe Anderson - Former Microsoft Access MVP)🇺🇸


What about just:

   DMax("[EventID]","tblEvents")

mx

ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)DatabaseMX (Joe Anderson - Former Microsoft Access MVP)🇺🇸

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of marku24marku24🇺🇸

ASKER

Use Dmax in place of Max?  What about the Where clause?  I need that to filter the recordset.

Avatar of marku24marku24🇺🇸

ASKER

The MyEventID worked - I have no idea why but that came back with the answer

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

Microsoft Access

Microsoft Access

--

Questions

--

Followers

Top Experts

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.