Results 1 to 9 of 9
  1. #1
    New Lounger
    Join Date
    Nov 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    When are autonumbers assigned on a form?

    <P ID="edit" class=small>(Edited by WendellB on 03-Nov-04 11:30. Changed subject to clarify - Was Access 2000)</P>If i open a form it automatically assigns a new autonumber even without adding a record. If i go to the table it does not? Where in the form design does it indicate to add the number on opening the form?

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: When are autonumbers assigned on a form?

    It depends on how your form opens up - if it is set to do data entry (a form property), then it will automatically start a new record and the autonumber is generate the minute you set focus on a field and begin to type. If your form is not set for data entry, then it should not be assigning an autonumber until you start to create a new record. If I've misunderstood the question, please post back.
    Wendell

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: When are autonumbers assigned on a form?

    It is quite likely that you have some code in your form's Current event (or perhaps the Open event) that is setting a field value, which is causing the form to be "dirty". As soon as Access detects this (if you are on a new record) it assigns the autonumber.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  4. #4
    New Lounger
    Join Date
    Nov 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: When are autonumbers assigned on a form?

    Yes the code was in the open event. I removed the code and the autonumber is fine. I would like the form to open at the new record instead of record 1, to prevent user overwriting. I assume the code I deleted did this. Is there a simpler way?

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: When are autonumbers assigned on a form?

    If you set the Data Entry property of the form to Yes, the form wil always open to a new record. Downside is that the user won't see the existing records.

    If you want the form to display existing records, but move to a new record when it is opened, you can use

    RunCommand acCmdRecordsGoToNew

    in the On Open or On Load event of the form. In itself, this will not assign a new AutoNumber, but there might be other code behind the form that causes a new AutoNumber to be assigned, for example in the On Current event of the form.

  6. #6
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: When are autonumbers assigned on a form?

    The code to move to a new record would not have caused the autonumber problem. In your code, you might have had something like this:

    txtOrderDate = Date()

    Only this kind of code that changes a field value will cause the new autonumber to be generated.

    (I see Hans gave you the code to move to a new record.)
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: When are autonumbers assigned on a form?

    Shouldn't that be DefaultValue?

  8. #8
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: When are autonumbers assigned on a form?

    <P ID="edit" class=small>(Edited by Francois on 04-Nov-04 17:22. Change Default in DefaultValue)</P>If you want to assign a value to a textbox when the form open or when the you move to a new record without create a new autonumber, you can use the default value.
    Me.MyTextbox.DefaultValue = "#" & Date & "#"
    can be used in the On Open, On Load or On Current event of the form and will enter todays date in MyTextbox without creating a new autonumber.
    Francois

  9. #9
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: When are autonumbers assigned on a form?

    <img src=/S/blush.gif border=0 alt=blush width=15 height=15> Post edited
    Francois

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •