Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2008

    Red face Unanswered: Creating the primary key based off of non-key values in a form

    Hi guys,

    I am using Microsoft Access 2007. I created a form to add parts to the part table. The [PartNumber] which is the primary key for the table, is suppose to be composed of different values. The first of which is the [PartDesignation], which is the series.

    So to start out, I just want to place the value the user enters in the [PartDesignation] field into the [PartNumber] field. Later on I will concatenate other values that make up the part number, but for right now I just want to get one single value to go in there.

    Any help would be appreciated!

    Option Compare Database

    Dim partNumberString, seriesDesignationString As String

    Private Sub Form_AfterUpdate()
    partNumberString = seriesDesignationString
    Me.[PartNumber].Text = partNumberString
    End Sub

    Private Sub PartDesignation_AfterUpdate()
    seriesDesignationString = Me.[PartDesignation].Text
    End Sub

  2. #2
    Join Date
    Nov 2007
    Adelaide, South Australia
    I wouldn't do it. Just let the PartNumber be an Autonumber. Then in any query, form or report you can show a "partcode" or whatever you want to call it and just calculate it.

    If you still want to do it that way, you could also just use an incredibly simplified code:

    Private Sub Form_BeforeUpdate(Cancel as Integer)
    Me.[PartNumber] = me.PartDesignation
    End Sub

    And go from there.
    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