Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 364
  • Last Modified:

MS Access VBA - Help with DLookup function

Okay, I am looking to use the DLookup function to populate a variable. I want to use the DLookup function or some SQL Code that will check to see what the maximum value is in the table. I will then assign that value to a variable.
Then I will increment the same variable by 1 (alot like a database sequence).
0
jonsuns7
Asked:
jonsuns7
2 Solutions
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:


Dim x
x= Nz(DMax("SomeField","SomeTableOrQuery","<OptionalCriteria>") , 0)

mx
0
 
NorieData ProcessorCommented:
Why not DMax?

x= DMax("[Field1]", "tblTableName", "[Field2]=10")

0
 
Jeffrey CoachmanMIS LiasonCommented:
...then perhaps

x=x+1

Or

Dim lngCurrent as long
Dim lngNext as long
lngCurrent = DMax("[Field1]", "tblTableName", "[Field2]=10")
lngNext =lngCurrent +1

I am sure you get the idea...


Jeff
0
 
jonsuns7Author Commented:
Both solutions were similar and came in at about the same time.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now