Setting up Customer ID as Primary Key

Anonymous
2015-04-07T14:28:40+00:00

Hello everyone,

First of all, I am very new to Access and this is my first time working in it.  I currently have a database in Excel that I would like to implement in Access. 

I am trying to create a customer database that consists of 4 different tables:

  1. Customer Contact Information
  2. Customer Profile Form
  3. Customer Order Form
  4. Customer Order Content

I want my primary key, I believe that is the correct term, to be the Customer ID.  I would like this to be a calculated field in the "Customer Contact Information" table and it should be manually inputted into the other tables.  The "Customer Contact Information" table and the "Customer Profile Form" should have the same exact number of rows since each customer will have only 1 profile.  If possible, I would like the Customer ID field to just copy over to the "Customer Profile Form".  

The "Customer Order Form" and "Customer Order Content" will have varying rows since each customer could place multiple orders or have multiple items per order.  I would like a unique Order Number to be generated in the "Customer Order Form" and the Customer ID, which would be manually inputted, would still be the primary key that ties it back to the "Customer Contact Information" table.  Then, in the "Customer Order Content" I would like the Customer ID and Order Number to be manually inputted as well.  The Order Number would l link back to the "Customer Order Form" and the Customer ID would still be the primary key.  

My goal is to create a form on top of all of this so when customer data needs to be inputted, Customer ID is simply automatically generated and pastes to the appropriate fields in the other tables.  The user will ultimately be able to click "New Customer" and then begin inputting all the fields for the "Customer Contact Information", "Customer Profile Form", and "Customer Order Form".  Then, the user will have to come back later to input the "Customer Order Content" since everything is purchased based on their preferences.  This is where it gets confusing for me since I have to keep all the tables related based on Customer ID,  but 2 of the tables will have different numbers of rows.

The problem with the current system is that it gets difficult to share the database and input the data with a few users since there are so many columns and no real interface.

Any help in setting up this database in Access would be greatly appreciated or if anyone has any other suggestions. 

Thank you for taking the time to read this.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

55 answers

Sort by: Oldest
  1. Anonymous
    2015-04-23T22:02:58+00:00

    For that you'd use the NotInList event procedure of the ColorID combo box in the subform to insert a row into the Color table:

    Private Sub ColorID_NotInList(NewData As String, Response As Integer)

        Dim ctrl As Control

        Dim strSQL As String, strMessage As String

        Set ctrl = Me.ActiveControl

        strMessage = "Add " & NewData & " to list?"

        strSQL = "INSERT INTO Color(Color) VALUES(""" & _

                NewData & """)"

        If MsgBox(strMessage, vbYesNo + vbQuestion) = vbYes Then

            CurrentDb.Execute strSQL, dbFailOnError

            Response = acDataErrAdded

        Else

            Response = acDataErrContinue

            ctrl.Undo

        End If

    End Sub

    When the user types a new colour into the combo box they'll be prompted to confirm the addition of the new item to the list, and on their answering yes, the code executes an SQL statement to insert a row into the table.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2015-04-24T00:02:39+00:00

    Worked perfectly as well.

    Is there a way to make it so that certain fields can't be modified unless a field has a specific value?

    There is a Yes/No column in my table and if the answer is "Yes", I would like only certain fields to be modified so the user can enter data.  However, if "No" is selected, I would like a different set of fields to be modified for data entry so certain fields should remain grayed out. Also, there are a few "Other" options in some of my lists so if "Other" is selected, I would like the user to be able to input data into a text field next to it, otherwise it should remained grayed out.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2015-04-24T11:11:34+00:00

    For future reference, when introducing a new topic, please start a new thread rather than tacking it on to an existing one.

    You need to do this in two places, so to avoid duplication of the code put it in a function in the form's module.  Assuming you have a check box as the control for the Boolean column:

    Private Function EnableControls()

       ' set check box to False by default

       Me.[YourCheckBox].DefaultValue = """" & False & """"

       ' enable one set of controls if Boolean column is True

       Me.SomeControl.Enabled = Me.[YourCheckBox]

       Me.SomeOtherControl.Enabled = Me.[YourCheckBox]

       ' etc

       ' enable another set of controls if Boolean column is False

       Me.AnotherControl.Enabled = Not Me.[YourCheckBox]

       Me.YetAnotherControl.Enabled = Not Me.[YourCheckBox]

       ' etc

    End Function

    You can then call the function as both the form's On Current event property and as the AfterUpdate event property of the check box with:

        =EnableControls()

    However, there is one fly in the ointment.  If the user checks the check box, but then undoes the record with the Esc key the controls will remain enabled/disabled, the opposite of what they should be.  Checking and unchecking the check box will return the properties to their correct values, but this is not satisfactory.  One would imagine the form's Undo event procedure might be the answer, but this executes before the record is undone, so doesn't help.  At present I don't know any way of solving this, but will post a thread later to see if anyone else has a solution.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2015-04-26T17:32:53+00:00

    Okay, I will make a new topic in the future. Thanks for your assistance with all of that. I am currently applying everything I have learned here to the actual database. Everything seems to be working as intended so far and it looks much better than before.

    I'm still working on the feature to enable some controls and disables others based on either a Yes/No or "Other" selection in a Combo List. It would be ideal to have this feature, but it isn't crucial right now.

    I have one question pertaining to a topic discussed earlier in the thread about the junction tables and subforms. If a user selects a Color by accident and tries to remove the color, it brings up the error message saying "You must enter a value in the [name] field." I have AllowEdits and AllowDeletions enabled on the Main form and Subform, but I can't find any option to delete the entry either by right clicking the combo box or the right clicking the record selector. I can hit "Delete Record" through the Home ribbon and remove the record, but nothing within the form itself. 

    Is there anyway to remove a record through the subform or form itself? Maybe if it detects a blank value, then don't save the record or delete it? 

    Would something like the below work?

    If

    Me.cboColor = ""

    Then [delete record]

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2015-04-26T17:57:02+00:00

    You must either undo the incorrect colour selection by pressing the Esc key before saving the subform record, or if the record has been saved, delete the record by clicking on the record selector to select it and then pressing the Delete key.

    Was this answer helpful?

    0 comments No comments