Results 1 to 3 of 3
  1. #1
    shod90 is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Jan 2016
    Posts
    134

    increment by 1 every button click

    Dear All,
    um working on cashier system and need to set the transaction ID to be incremented every time by one when the user click New Order .. And the text box that holds the transaction ID (which refers to TransactionID in tblOrders) to remember the last number was incremented and save it to tblOrders.
    I don't want to use Autonumber , Sometimes makes troubles .



    Hope you understood me .

    Thanks in advance.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Autonumber is the easiest,passive, problem free method.

  3. #3
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    The Access gurus say that autonumbers should never be used as meaningful data and never shown to the user. So what's good enough for them...
    However, if you don't care whether or not the number is sequential and/or has no gaps, then maybe.
    The main issues with sequential numbering arise in two situations, assuming the table field for this number is indexed, no dupes.

    In a multi-user db, it is possible to run into conflicts if the same calculated number is being used by concurrent users. When the second goes to save, it fails and at worst, the record is lost. Second is that if a record is started and the sequential number is calculated and stored in some seed table, the user may cancel the record creation. If that happens, there is a gap in the sequential numbering.

    The only ways I know that are somewhat reliable are as follows (in either case, the likelihood that concurrent users attempt to create a record at the same millisecond is virtually impossible):
    - create and save the record at the very beginning if you need to display the number at the start, and don't allow the record to be canceled. If during the record creation it is decided the record is not required, provide for a 'cancellation' flag of some sort on that record. A query for these records can either be filtered to not show 'canceled' or can identify which ones were canceled to show why you might not be able to locate a printed copy of a PO, for instance. Usually this is not possible if there is a sub form whose records relate to the sequential number.

    - create the number at the end of the process and display it then. It pretty much ensures that if one is going to effect a save after filling out the form, the record is, in fact, required, although providing a means of cancelling such a record may not be a bad idea, depending on the business case.

    - use temp tables. If you don't have the unique sequential number, at the very least you need a temp unique identifier on the main form, such as the user id, in order to create the child records. Once the record is complete, write the parent/child records to their tables.

    In either method, the number would be calculated using the DMax function on the sequential number field (easier than DLookup). That would be my preference over using some autonumber field to find the last record. The form probably needs a Save and Save/Close button in addition to whatever else seems suitable (such as Cancel) if the record creation starts with the number. Save to commit the number, the Save/Close to save any changes made to the form when user attempts to close it (since the record is incomplete when the number is generated).
    Last edited by Micron; 12-17-2016 at 10:21 AM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Increment number field on button press.
    By Homegrownandy in forum Access
    Replies: 3
    Last Post: 03-11-2016, 05:54 AM
  2. Replies: 9
    Last Post: 03-31-2015, 04:13 PM
  3. Replies: 23
    Last Post: 04-18-2013, 09:31 PM
  4. Replies: 15
    Last Post: 05-17-2012, 01:12 PM
  5. Increment a value on button click
    By michaeljohnh in forum Programming
    Replies: 9
    Last Post: 08-25-2010, 10:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums