This is not difficult, but it takes a bit of setting up because there are a lot of steps. You will need the following:
1. Two tables: Events (fields are EventID, Year, Track and Race) and Results (Fields are ResultID, EventID, Position, Driver and other relevant fields). The tables are related via the EventID fields, with referential integrity enforced.
2. An unbound Search form. This contains three combo boxes and a textbox, all unbound. These controls will be used to filter data from the Events table. The combos are cmbYear, cmbTrack and cmbRace; the textbox is EventID
3. 2. A subform called Results Subform, based on the Results table.
Top of the cascade is cmbYear, which displays a list of years for which you have race information. Next is cmbTrack, which displays results filtered on cmbYear. Third is cmbRace, which shows races for a particular race meeting. This is filtered on both cmbYear and cmbTrack. Finally, EventID is a text box which displays the EventID field from cmbRace. The subform then displays results from this unique event.
OK, details for the frmSearch form. This is being presented in shorthand to save space on the reply, but all information is there.
Create a blank form. With the Control Wizard OFF, drag 3 combos and one text box onto the form. Save it as ResultSearch.
First Combo. Right-click, select Properties, click the All tab. Set these properties:
Name cmbYear
Row Source Type Table/Query
Row Source SELECT DISTINCT Events.Year FROM Events;
Column Count 1
Column Widths 3
Second Combo, still on the All tab:
Name cmbTrack
Row Source Type Table/Query
Row Source SELECT DISTINCT Events.Track FROM Events WHERE (((Events.Year)=[cmbYear]));
Column Count 2
Column Widths 3;0
Third Combo:
Name cmbRace
Row Source Type Table/Query
Row Source SELECT Events.EventID, Events.Race FROM Events WHERE (((Events.Track)=[cmbTrack]) AND ((Events.Year)=[cmbYear]));
Column Count 4
Column Widths 0;3;0;0
Now switch to the Events tab. Double-click in the After Update event line for each of the 3 combos. You will see [Event Procedure] in each of the lines. Click the builder (…) button on any one of them to be taken to the code for the form. Copy and paste until the form looks like this:
Option Compare Database
Option Explicit
Private Sub cmbRace_AfterUpdate()
[EventID] = [cmbRace].Column(0)
End Sub
Private Sub cmbTrack_AfterUpdate()
[cmbRace].Requery
[EventID] = ""
End Sub
Private Sub cmbYear_AfterUpdate()
[cmbTrack].Requery
[EventID] = ""
End Sub
Explanation:
The Requery commands cause the combos to refresh their contents, so the lists are updated based on the upstream data.
[EventID]=”” blanks the EventID textbox, removing display of records in the subform.
[EventID] = [cmbRace].Column(0) pushes the Event ID from cmbRace into the EventID textbox, so the subform can update and display the filtered data.
Save the form.
Now, the subform.
Create an Autoform based on the Results table. In Design view, change the Default View to Datasheet. Save the form as subResults, and close it.
Back to the main form. Open the search form in Design view. Restore so you can also see the database window. Drag the subform icon onto the main form and release it. You will be prompted for a name; take the default.
Now, click the subform ONCE and go to its properties. You should see Link Child Fields and Link Master Fields. Enter EventID into each line, and save the form.
View the data and give it a run. You should also be able to use the subform for data entry.
Denis