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: Most helpful
  1. Anonymous
    2015-04-23T21:26:00+00:00

    That worked perfectly. I will have to do some more research on that code to get a better understanding of it though. 

    Would it be a similar procedure for the Color subform? If I wanted to allow the user to create a new entry into the Color subform to add a color that wasn't there? If I were to add some event procedure or code into the fsubCustColorPreference form, would it be applied or inherited if I were to use it as a subform in frmCustomers?

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2015-04-23T17:47:24+00:00

    For a combo box to both navigate to a customer record, and go to a new record (thus avoiding the need for a separate button) you'd replicate that in my demo by having the following as the combo box's RowSource:

    SELECT CustomerID,

    FirstName & " " & LastName, 1 As SortColumn,

    LastName,Firstname  

    FROM Customers  

    UNION

    SELECT 0, "<New Customer>", 0,"",""  

    FROM Customers

    ORDER BY SortColumn, LastName, FirstName;

    It's other properties would be:

    BoundColumn:   1

    ColumnCount:    2

    ColumnWidths:  0cm

    If your units of measurement are imperial rather than metric Access will automatically convert the unit of the last one to inches.  The important thing is that the dimension is zero to hide the first column.

    The code for the combo box's AfterUpdate event procedure would be like this:

        Const MESSAGETEXT = "No matching record"

        Dim ctrl As Control

        Set ctrl = Me.ActiveControl

        If Not IsNull(ctrl) Then

            If ctrl = 0 Then

                ' go to new record and move focus to FirstName control

                DoCmd.GoToRecord acForm, Me.Name, acNewRec

                Me.FirstName.SetFocus

            Else

                With Me.RecordsetClone

                    .FindFirst "CustomerID = " & ctrl

                    If Not .NoMatch Then

                        ' go to record by synchronizing bookmarks

                        Me.Bookmark = .Bookmark

                    Else

                        MsgBox MESSAGETEXT, vbInformation, "Warning"

                    End If

                End With

            End If

        End If

    The code for the form's Current event procedure would be:

        ' synchronize go to contact combo box

        ' with current record

         Me.cboGotoCustomer = Me.CustomerID

    where cboGotoCustomer is the name of the combo box.

    The code for both the form's AfterUpdate event and AfterDelConfirm event procedures would be:

         ' requery go to contact combo box

         ' to reflect changes to data

         Me.cboGotoCustomer.Requery

        ' synchronize go to contact combo box

        ' with current record

         Me.cboGotoCustomer  = Me.CustomerID

    With a bound form you don't need a button to save the record.  This is automatically done when you move to another record, close the form or explicitly save the record in some other way such as clicking on the record selector.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2015-04-23T16:57:46+00:00

    I am having trouble controlling the Record it's at with the combo box with using the tabs. I want to be able to navigate the records, as you have in your demo, and I want to be able to add new records too. I added a "Add Customer" button to add a new record and a "Save Customer" to save the information and refresh the page. I don't want them to be able to add new records with the combo box, just go to that record. I tried using a macro for "Go To Record", but it was not working.

    It is under the form: frmCustomers

    http://infernalrage.com/i/InfernalRage_2.accdb

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2015-04-23T10:40:01+00:00

    Is there a recommendation on using more than 1 form to enter data into 1 table?

    It's entirely a matter of your own choice.  Both will do the job.  If you use two forms, however, once you've entered all the data you have to open both to see it all.  A better solution would be to use a single form and put a tab control in it.  You can put controls bound to the primary fields on the first page of the tab control, controls bound to the secondary fields on the second page, and the colour preferences subform on the third page.

    In the form's header section you can include an unbound combo box to enable you to move to a selected customer record.  You'll find an example of a combo box used in this way in FindRecord.zip in my public databases folder at:

    https://onedrive.live.com/?cid=44CC60D7FEA42912&id=44CC60D7FEA42912!169

    If you have difficulty opening the link copy its text (NB, not the link location) and paste it into your browser's address bar.

    In the same OneDrive folder is also a FormsDemo file which includes an illustration of how to place subforms on pages of a tab control.

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2015-04-23T03:46:20+00:00

    Is there a recommendation on using more than 1 form to enter data into 1 table?

    I combined the Customer and CustomerProfile table into just a single Customer table so the customer demographics and the preferences are in one table. Currently, all the information is received at once, but in the future I may receive the customer demographic at one time and then the Customer Profile information at another time. Would it be better to split the tables up or use more than 1 form to enter the data?

    Was this answer helpful?

    0 comments No comments