473,394 Members | 1,852 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,394 software developers and data experts.

Fixed autonumber reset everyday

I have a field in a form that I want to have automatically generated a number. Specifically, it starts at 8000 and goes up by one every time a number is used. Multiple people will also be using this form at the same time.

So let's say Person A and Person B open the form at the same time, so they both get the same unused generated number. The goal of it is if Person A submits his form first, then I want Person B form to lookup records from the table. Then after the form detects if it was already used, have it pop up a message box saying "someone has already used this number, so your number will be the next unused number," and then the number will automatically go up by one upon submission.

Then have that series of numbers start all over, back at 8000 the very next day. If you need more clarification, please let me know. Any help on this would be appreciated.
Mar 6 '17 #1

✓ answered by jforbes

You could use the AfterInsert Event to grab the next number and stamp it on the Record. This way the number isn't shown or pulled until the user saves the Record.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_AfterInsert()
  2.     Me!AutoKey = getNextKey()
  3.     DoCmd.Save
  4. End Sub
  5.  
  6. Public Function getNextKey() As String
  7.     getNextKey = Val(Nz(DMax("AutoKey", "AutoKeyTest", "RecordDate=#" & Date & "#"), 7999)) + 1
  8. End Function

4 2197
jforbes
1,107 Expert 1GB
You could use the AfterInsert Event to grab the next number and stamp it on the Record. This way the number isn't shown or pulled until the user saves the Record.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_AfterInsert()
  2.     Me!AutoKey = getNextKey()
  3.     DoCmd.Save
  4. End Sub
  5.  
  6. Public Function getNextKey() As String
  7.     getNextKey = Val(Nz(DMax("AutoKey", "AutoKeyTest", "RecordDate=#" & Date & "#"), 7999)) + 1
  8. End Function
Mar 6 '17 #2
So thank you for providing this it has worked to some degree, it works but I changed the date on my computer manually to check to see if it would reset the number, the access form detects the date, but when the next day happens the number resets to 1 instead of 8000. I have tried playing around with the code, but have not found any viable solution to it.
Mar 7 '17 #3
I think I found out my problem will report back when I test it out.
Mar 7 '17 #4
No clue what I did haha I played with it and then when i'm looking at it, it's back to your original code and it works once again. Thank you for your help!
Mar 7 '17 #5

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

Similar topics

12
by: deko | last post by:
Is there a way to reset the AutoNumber sequence? I have several tables that use the AutoNumber field as the Primary Key, and I'd like to somehow do an Import/Export that will make remove the...
4
by: Todd Matson | last post by:
I have a table with an autonumber primary key column. When I add a row to the table, Access is generating a number which is already in use. This makes my application blow up. Thankfully, the...
2
by: N. Graves | last post by:
Hey is there a command like in SQL Transactional that will reset the Autonumber field to the highest number in the found in the field? I developing a access database with a several table that...
16
by: John Baker | last post by:
Hi: I know this is a strange question, but I have inherited a system where files are copied and records re auto numbered (as an index field) )frequently, and I am wondering how high the number...
4
by: Danny | last post by:
I have a db that has a table that is never deleted but just has records cleaned out "delete * from table" but each time it is populated, the autonumber is not reset to 0 and picks up where it...
3
by: trueblue7 | last post by:
I apologize if this question has been asked before... I'm trying to reset autonumber fields back to 1. The autonumber fields are part of the composite primary keys. I followed the MS help with...
4
by: lamkelf | last post by:
Hi all, I have found solution for previous Access versions (i.e. compacting database) but it doesn't work with the 2003 version. Can someone point me to a website or give me some hints. ...
9
by: Gogo | last post by:
Database has record 59 showing, tabing to enter data returns autonumber to 134. What happened to cause this, how would I fix it?
2
by: dougancil | last post by:
I have a user who had deleted some records from a database today using Access 2010. They have an ID field that's autonumbered. They have No Duplicates allowed. When they created a new record today,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.