473,395 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Get the number from the previous record

Morning all,

Hopefully someone can give me a pointer as I am having no luck finding a solution.

Each of my records needs an expense ID (i.e. P235-994-EXP-001).
I have code set up to extract the 1st 3 parts of the ID from the users selections on the main form but I need to lookup the previous forms last integer so I can increment it by one.

i.e. If P235-994-EXP-001 is the last record I need to lookup the "001" and increment it so my next record reads P235-994-EXP-002.

Not finding anything in any of the tutorials I have been using which mentions a method of doing this.

Cheers for any help!
Nov 28 '06 #1
3 1653
NeoPa
32,556 Expert Mod 16PB
You can't refer back to the previous form value but you might try something like :
Expand|Select|Wrap|Line Numbers
  1. Dim intNextVal As Integer
  2. Dim strNextID as String
  3.  
  4. strNextID = Left(Forms![MainForm].[ExpenseID],13)
  5. intNextVal = Right(DMax( _
  6.     "[ExpenseID]", _
  7.     "[ExpenseTable]", _
  8.     "[ExpenseID] Like '" & strNextID & "*'"), 3)
  9. strNextID = strNextID & Format(intNextVal+1, "000")
Obviously filling in the correct names for your table and fields.
Nov 28 '06 #2
And for the 2nd time you have saved me from a larger head ache!

I hadn't come across the DMax function before but you learn something every day.

Cheers!
Nov 29 '06 #3
NeoPa
32,556 Expert Mod 16PB
No Problem.
There is a whole family of D... functions called 'Domain Aggregate' functions.
DLookup(); DMin(); DCount(); etc.
Nov 29 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Carl | last post by:
I have a main form with navigation buttons on it and a label showing for example Record 1 of 15 using recordsetclone on it and eveything works fine. When I move through the records the record...
5
by: Steve Strik | last post by:
My Problem: I have created a database here at work that is exhibiting some very strange behaviour. Essentially the database is structured in a manner where one table is a master record table...
12
by: Martin Heuckeroth | last post by:
Hi Any idea on how to get a row number from the original table? We do a query and get a result. The row number from the result is different from the rownumber of the table the result originated...
6
by: TB | last post by:
Hi All: Here´s a very simple question: I have created a datatable inside a dataset, and subsequently selected a particular row using certain criteria. How do get the index number of that...
1
by: dympna | last post by:
HI I am trying to create a number field that will create a unique incremented number each time a record is added to the database via a form. but I want that number to be in sequence and start from...
8
by: Jeff | last post by:
A client wants a press of the Enter key in a field on a continuous form to grab the value of that field from the previous record. But if they have typed a value and then hit Enter it shouldn't. ...
1
by: roveagh1 | last post by:
Hi I've been using the 2 year old link below to repeat values from previous record field into current corresponding field. It's worked fine for text but the last piece of advice was to use the same...
5
by: Aboone | last post by:
Hello, I woudl like to dispaly the order number which has been entered into a previous record on a new record. I am unable to use an autonumber as our Order number format is constantly...
4
dlite922
by: dlite922 | last post by:
hey guys, I'm doing some brain storming and getting ideas to come up with a solution. I have a list of ....data... that is displayed 10 per page with the LIMIT clause. Simply put: My...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.