ApparentlyInept
You only want to store the primary key from your first table on your second table. This one of the major advantages of using a relational database. Imagine you are renting out videos or DVDs. You store the video title in your invetory table and identify each video with a primary key VideoID. In your RentOut table, you record the rentals -- rent what, when to whom and when the video was returned. Now suppose you also stored the video title in the RentoOut table along with the VideoID. Then either because of typing mistake, or a law suite, the title for a video has to be changed. In this scenario, not only do you have to change the title in video inventory table, but you now have to change the title for records in the RentOut table where the video in question was rented out. This is called "maintenance". By only storing the VideoID field in the RentOut table, maintenance is reduced, and anytime you need to look at the details for the video, you use the VideoID to find the record in the Video inventory table.
...Moving on to your database.
TableA
SerialNumber - primary key (right??)
ITAMS
Nomenclature
TableB
OnLoadID - primary key
SerialNumber - foreign key to TableA
CustomerID - see discussion
CheckOutDate - date field
BeforeCondition - short text
CheckInDate - date field
AfterCondition - short text
Comments - memo field
Disucssion:
Only the serial number is needed in this table. There is no need to include ITAMS and Nomenclature fields.
Customer - normally, you would have a customer table. Why? Well, you will probably want the to know their phone number, address, etc -- makes business sense. And if your business booms, hopefully, you will have repeat customers.
CheckIn and Out dates -- obviously, dates the equipment was loaned out and returned. Any records with a CheckOutDate and no CheckInDate will be out on loan. Probably a good idea to document the condition of equipment before and after.
...The combo box
A combo box can be used to return more than one field or column.
SELECT Serial Number, ITAMS, Nomenclature from TableA
The combo box can display the serial number. And then you can use two unbound text boxes to display the ITAMS and Nomenclature values with the AfterUpdate event procedure for the combo box.
Open the form in Design mode and make sure the Properties window is open (from the menu, View -> Properties)
Select the combo box.
First thing to do is change the name of the combo box to a more meaningful name if necessary. Select the "Other" tab in the Properties window. The name may display something like Combo16. Change it to
SerialNumber[/b]
Now select the "Data" tab in the Properties window and select the RowSource. Click on the "..." command button that appears to the right to open up the QueryBuilder.
Configure the query to display in order...
Serial Number, ITAMS, Nomenclature
Under the SerialNumber, sort Ascending.
Close the QueryBuilder and save your results.
BoundColumn: 1
Now click on the "Format" tab in the Properties window.
ColumnNumber: 3
ColumnWidths: .7";1";1" (Change as required -- these are the widths of the each column / field)
ListWidth: 2.7" (should match the total of ColumnWidths
Add two text boxes under the combo box, or wherever it makes sense. Select the each of the text boxes, and use the Property window to change the name of the controls to
txtITAMS
txtNomenclature
Now select the combo box again. Click on the "Event" tab in the Property window, click on the field for "AfterUpdate". Select "[Event Procedure]" from the drop down list box and click on the "..." command button to open up the VBA coding window. Type the following in blue...
Code:
Private Sub SerialNumber_AfterUpdate()
[COLOR=blue]
SetSerialNumber
[/color]
End Sub
[COLOR=blue]
Private Sub SetSerialNumber()
If Len(Nz(Me.SerialNumber, "")) Then
Me.txtITAMS = Me.SerialNumber.Column(1)
Me.Nomenclature = Me.SerialNumber.Column(2)
Else
Me.txtITAMS = ""
Me.Nomenclature = ""
End If
End Sub[/color]
Now go back to the form design window and select the form by clicking on the top left square box where the vertical and horzontal rulers meet. Click on the "Event" tab in the Properties window, select the Oncurrent field, and click on the "..." command button to go back to the VBA coding window. Type what is displayed in blue...
Code:
Private Sub form_Current()
[COLOR=blue]
SetSerialNumber
[/color]
End Sub
Save your form and your code and try the combo box box. This is what shoudl happen.
If the current record has a valid SerialNumber or if a valid SerialNumber is selected, Access runs the SQL SELECT statement which retrieved the three fields. The SetSerialNumber subroutine you created then displays the values in the two text boxes.
Note:
Spelling is real important here. If you spell the name of a control text box or combo box incorrectly, or the name of a command wrong, the code will not work.
...Moving on, improvements.
You may find it helps to change the name of your tables to more meaningful names. For example...
tblEquipment - for TableA
tblRental - for TableB
Avoid using spaces and special characters in the name of your tables, fields, etc. Otherwise, it makes it more awkward later own when creatnig forms or code.
Richard