Access 2007-2016
Access 2000-2003
Access Seminars
TechHelp Support
Tips & Tricks
Access Forum
Course Index
Topic Glossary
Insider Circle
Home   News   Tips   Glossary   Templates   Forums   Help   Logon   Order   Contact Us  


Microsoft Access Forum
By Richard Rost   Richard Rost on Facebook Richard Rost on Twitter Richard Rost on Google Plus Richard Rost on LinkedIn Email Richard Rost

This forum is for the discussion of Microsoft Access.

Access is my personal specialty. Have questions? Comments? Want to discuss how to do something? Post it here. Also, I get a LOT of questions sent to me in Email from people around the world. I'll post the interesting ones in here. Feel free to comment on them.

Click Here To Subscribe to this forum and receive an email update whenever new posts are added, just scroll down to the bottom of this page and enter your email address in the comment form.

Permanent Link
Keywords: microsoft access forum
Post New Topic

Read Automatic transaction number by Gioia H @ 4/29/2017
Yay thanks i figured it out. I made two queries to get it to work the first:
SELECT DISTINCT DMax("PurchaseOrderID",'tblPurchaseOrders')+1 AS [Max], Format(Now(),"yyyymm") AS Now
FROM tblPurchaseOrders;
Then the second one: SELECT "K" & [Now] & "" & [Max] AS NewPO
FROM qryNewPOCalculate;

Not perfect but works. Good idea about the Dmax function. Thanks
Show Just This Thread        Post Reply
Read Automatic transaction number by Gioia H @ 4/22/2017
I'm trying to do something similar. I want to create a customer order number that would start with the letter K then take the year and month then increment from there. (K201704...) This info would populate my order text field on a form automatically. Can you help?

Reply from Alex Hedley:

Microsoft Access DMax Counter
Show Just This Thread        Post Reply
Read Automatic transaction number by Gregory C. S @ 4/7/2017
Oops, besides a couple English typos like writing "an" instead of "and", I left out one of the 8 characters in 80010999 so the next number would be 800011000. And, I, accidentally, had a space after the first bracket in [TransactionNum]. Sorry.
Show Just This Thread        Post Reply
Read Automatic transaction number by Gregory C. S @ 4/6/2017
The tip below is crude, but it works for me.
On 2/17, I made two posts called "How to increment a number by one."  It was actually how to increase a combination of text and number by one.  For each day, pretend this year's leading text
part is 7362.  Use the technique shared with me posted on 2/17 to separate your number into 3 parts.  7 + middle three and right 4.  Add one to the middle 3 for the day and then add one to the right 4 during the day.  Annoyingly, you will have to manually change your starting point each day unless you can figure out how to ask the system clock for the day of the year.  In my case, I only need to change the left few once per year, but in your case, you could, each day, until you figure out better, add a transaction before others have access to the transactions, overwrite that transaction with a starter number.
If yesterday's transactions was, say, 70401581, then the code would create 70401582. Overwrite that with 70410999.  The first transaction of the day with the autoincrement will be 70411000.  Yearly, manually, do the same thing. Create a new transaction at the end of the year an overwrite.  Suppose the last transaction this year is 73651702.  Overwrite the new record with 8001999.  The first transaction will be 70011000.  Crude but it will work until you find a better way.  Modifying the code I posted on 2/17, you code would look similar to:

DoCmd.GoToRecord , , acNewRec
Dim varResult As Variant
' in DMax(), use the FieldName and the TableName, respectively
varResult = DMax("TranactionNum", "tblTransaction")
' This next part separates (parses) the text from the number part,
' adds 1; then puts the parts back together with leading zeros.
Me.[ TransactionNum] = Left(varResult, 4) & _
Format(Val(Right(varResult, 4)) + 1, "0000")
Show Just This Thread        Post Reply
Read Automatic transaction number by Steven K @ 1/4/2017
Hi Alex. Happy New Year! Thank you for the recommendation. I think the composite key will be very useful for me for some of the applications in the DB I am working on, but for the specific purpose of what I am trying to do, it will not work or at least I need to do some kind of hybrid perhaps between a composite and what I need.

For example, I am in the financial services industry. I have traders that work in derivatives, others in equities, others in fixed income, etc. I am setting up separate tables for each products area, i.e. - EquitiesTradesT, FixIncTradesT, DerivativesT, etc. For a variety of reasons (regulatory, compliance, record keeping, trade report production,daily P&L, trader commissions, etc.), I need to have a common format of a Trade ID across all product trades.

I am keeping a regular autonumber ID for each table for the purposes of relationships, however, I need the "general" TradeID to have the format I mentioned in my original post. Therefore, in each table, I will have the exact same field, for the purposes of this forum, let's just call it, "TradeID". Let's say the first trade of the day is a fixed income trade with today's date, 01/04/2017. In the FixIncTradeT, the TradeID field, it should generate the number 70041000, i.e. - "7" for 201"7", "004" for the 4th day of the year, and "1000" for the first trade. The next trade is equities. The TradeID field in the table EquitiesTradesT will read 70041001, and so on.

Tomorrow will start at 70051000, i.e. - "7" for 201"7", "005" for the 5th day of the year, and "1000" for the first trade, etc. On December 31st, 2017, the first trade would be 73651000.

I know it seems a little confusing, and quite a bit of detail, and truthfully, it seems a little complicated, but it is necessary.


Reply from Alex Hedley:

So you can use the Day(), Month(), Year() functions passing in Date() then you could use something like Right(Year(Date()), 1) to get the 7 from 2017.

For the TransactionId you could have a Transaction table with one Field, TransactionId which is a number and every time you create a record anywhere in your db you increment this number. Now just get this number and add 1 each new record.
There could be race conditions and if multiple people are using the db at the same time it could get messy but it's an idea.
Show Just This Thread        Post Reply
Read Automatic transaction number by Steven K @ 12/28/2016
I am more or less an advanced level user in Excel, but I am relatively new to Access. I am hoping someone may be able to help me here. I work in a business that I have sometimes hundreds of transactions per day (I'm in the financial services industry). I have different tables for different types of transaction types. I don't want to mess with the Autonumber for each table, but I need to create a unique transaction number across all types of transactions. I need to create a "Trans # Field" and I need it in the following format... last digit of the year (i.e. - "6" for 2016)+ the day number of the year (i.e. - today 12/28/2016 would be 363 accounting for the leap year) + a number starting at 1000. For example, today's transactions would be 63631000, 63631001, 63631002, etc. Tomorrow, 63641000, 63641001, 63641002, etc.

Would it be possible to use an Expression in the Property Sheet or perhaps this would only be able to get done in VBA?

Thanks and happy holidays!

Reply from Alex Hedley:

How about a Composite Key?
Show Just This Thread        Post Reply

Collapse All Topics


Post Your Comments or Subscribe
    If you would like to be notified of new posts on this forum,
    just enter your email address below. It will be kept private.
If you just want to subscribe to get email updates when this forum is updated, then enter your name and email address and check the Notify Me box below. If you would optionally like to add your comments below to be posted, they are welcome.
  Your Name:  Required
  Your Email:  NOT Public


Sorry about this step. It's just to keep the spam bots away:
  Verify: What is 2+2:
  Notify me when the this forum is updated
  Remember Me for my next comments
Please do not use this form for Customer Service inquiries! If you have questions about your account, shipping info, courses you've ordered, need passwords, etc. please use the Customer Service Center instead.

I value your comments. They will be displayed on this page (above). Your name will be displayed, but your email address will not be.
As always, I promise to never give away your personal information to anyone else, ever.

NOTE: If you don't leave your name and email address, DON'T expect a reply. I can't promise a personal reply to everyone who posts here. I TRY my best, but I cannot guarantee it. If you don't leave your real name and email address, I won't even bother. I usually just hit DELETE. -Richard



You may want to read these articles from the 599CD News:

11/20/2018Microsoft Access Developer 12
8/25/2018NEW: Access Dev 9, 10, 11
8/25/2018Microsoft Access Developer 11
8/25/2018Microsoft Access Developer 10
8/25/2018Microsoft Access Developer 9
8/23/2018Access Dev 11 is ONLINE
8/17/2018Access Dev 10 is ONLINE
8/15/2018Access Tip: Search Form
8/15/2018Access Tip: Locked v. Enabled
8/15/2018Access Dev 9 is ONLINE

Visual Basicindex
Account Login
Online Theater
Lost Password
Free Upgrades
Insider Circle
Student Databases
Change Email
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search Our Site
Waiting List
Production Schedule
Collapse Menus
Live Chat
Customer Support
WalkThru Tutorials
Consulting Services
About Us
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Video Tutorials
MYOLP Memberships
Idiot's Guide to Excel
Volume Discounts
Payment Info
Terms of Sale
Gift CDs
Live Chat
General Info
Support Policy
Contact Form
Email Us
Mailing Address
Phone Number
Fax Number
Course Survey
Facebook    Twitter

Google Plus    LinkedIn

Blog RSS Feed    YouTube Channel
Richard Rost Microsoft MVP