Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2007
    Posts
    148

    Unanswered: generate primary key

    My form has two subforms and both of the subforms depends on the primary key in the main form to work.

    My problem is when I add a new record, the primary key doesn't generate immediately. I will have a primary key only after I enter information in one of the controls in the main form. If a user decided to work on the subform before entering any value in any of the controls in the main, it will be a MESS. Everybody will complain about missing the primary key. Even if I enter information in one of the controls to generate the primary key later, IT WILL BE TOO LATER. All my subforms are not happy.

    My question is how can I generate the primary as soon as I add a new record? I actually have control to store the current date but this still doesn't tricker Access to generate a primary key for this new record. Not until I enter information into one of the controls in the main form.

    thanks in advance

  2. #2
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    In the On Current procedure.

    If Me.NewRecord then Me.DateField = Date() will do it.

    Sorry for the rushed response :P
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  3. #3
    Join Date
    Sep 2007
    Posts
    148
    it works, thank you very much.

    P.s. I used your suggestion, just let user to delete any record. I set a condition to locked the record (that is take away the delete buttons and locked down all the controls) only when the user click the approved button.

    Thanks so much.

  4. #4
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Happy to help
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

Posting Permissions

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