Results 1 to 4 of 4
  1. #1
    kets0985 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2015
    Posts
    7

    Primary key auto populate in form

    Hello,

    I have a form which I use to record the daily activities. To track each activity time, I have used timer in the form. However, when I open a form, the record_ID which is the primary key, always autopopulate. Even when I click cancel or submit, the field takes the autonumber without been given a command for new record.

    In the form load event, I have a code as "DoCmd.GoToRecord , , acNewRec".

    What should I do, so the record_ID field should not take autonumber untill I give new record command.

    The main issue is, due to the record_ID error, the record which are there in the datasheet table does not reflect in the form when clicked on them. These records are kept on hold and when needed they can be reworked on once clicked.



    Click image for larger version. 

Name:	7-22-2015 6-49-36 PM.png 
Views:	10 
Size:	166.4 KB 
ID:	21366

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    If you start a new record , you get a new autonum. (blame microsoft)
    BUT, if you start entry in an 'entry table' (not connected to the main data)
    then click save, that will fire an append query to add the record. No wasted autonum.
    and not subform errors due to new autonum.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by kets0985 View Post

    ...Even when I click cancel or submit, the field takes the autonumber without been given a command for new record....

    ...In the form load event, I have a code as "DoCmd.GoToRecord , , acNewRec"...
    But you have given the command for a New Record! That's what the above, in red, is telling Access to do!

    That aside, it shouldn't matter if the Autonumber is wasted! Autonumbers should not be used for anything other than the Primary Keys! Things like serial numbers, account numbers, employee numbers should be something other than Autonumbers.

    Linq ;0)>

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    The acNewRec parameter sets focus to new record row, however, AFAIK new record is not actually initiated until some data is input to a field, either by user or by code. This initiation of record will trigger generation of autonumber. If record is then canceled and not committed to table, the autonumber is still 'used up' but no record is associated. This is the nature of autonumber field in Access.

    It is possible to programmatically 'recover' lost autonumbers but this is tricky and seldom justified.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. How to auto populate a form
    By e51lrrp in forum Forms
    Replies: 42
    Last Post: 03-20-2014, 11:40 PM
  2. Sub Form auto populate
    By keiath in forum Forms
    Replies: 4
    Last Post: 02-14-2014, 02:59 PM
  3. How to auto populate in tex box form
    By kft10 in forum Forms
    Replies: 3
    Last Post: 06-12-2013, 11:47 PM
  4. Auto Populate form
    By fpsmi in forum Access
    Replies: 1
    Last Post: 09-16-2011, 09:24 AM
  5. Auto populate a field (without a form)
    By DonL in forum Access
    Replies: 1
    Last Post: 06-21-2011, 03:19 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