Your Forms do not need to show any more information than you wish --
just hide or delete any fields that you do not need.
There's nothing wrong with using a Command Button, but I am not
convinced that it's necessary. You could simply set the "On Click"
property of the list in the master Form to re-filter the datasheet.
Anyway, I set up some Tables and Forms to do something like what you
described.
Here are the Tables:
[SiteName] Table Datasheet View:
SiteNameID Name
----------- -------------
-1695578594 Moscow
-535197881 Point Barrow
46567804 Atlantis
155682225 Death Valley
[Weather] Table Datasheet View:
SiteNameID description Date
----------- ----------- -----------
-1695578594 Cold 12/11/2005
-1695578594 Dry 12/2/2005
-535197881 Cold 12/11/2005
46567804 Wet 12/11/2005
155682225 Hot 12/1/2005
155682225 Dry 12/2/2005
Query [Q_SiteNames] displays the place names in sorted order.
[Q_SiteNames] SQL:
SELECT SiteName.SiteNameID, SiteName.Name
FROM SiteName
ORDER BY SiteName.Name;
[Q_SiteNames] Query Datasheet View:
SiteNameID Name
------------ -------------
46567804 Atlantis
155682225 Death Valley
-1695578594 Moscow
-535197881 Point Barrow
Query [Q_Weather] displays selected records from the [Weather] Table.
[Q_Weather] SQL:
SELECT Weather.SiteNameID, Weather.description,
Weather.Date
FROM Weather
WHERE (((Weather.SiteNameID)
=[Forms]![F_Sites]![lbxMain]));
[Q_Weather] Query Datasheet View (if "Moscow" was selected in Form
[F_Sites]):
SiteNameID description Date
----------- ----------- ----------
-1695578594 Cold 12/11/2005
-1695578594 Dry 12/2/2005
I defined a Form, [F_Sites], with the following properties:
Record Source = Q_SiteNames
and containing a List Box, [F_Sites]![lbxMain], with the following
properties:
Row Source = Q_SiteNames
Bound Column = 1
Column Count = 2
Column Widths = 0;1
On Click = [the following Event Procedure:]
Private Sub lbxMain_Click()
Me.Recordset.FindFirst _
"SiteNameID=" & Me.lbxMain.Value
' Close F_Subform if it's open
DoCmd.Close acForm, "F_Subform"
' Requery F_Subform
DoCmd.OpenForm "F_Subform", _
View:=acFormDS, _
DataMode:=acFormReadOnly, _
OpenArgs:=acNormal
End Sub 'lbxMain_Click()
For the Subform, I merely ran the Form Wizard on [Q_Weather] and named
the new Subform [F_Subform]. It's not really a Subform, though, just a
separate Form that we're treating like a Subform. You might want to
hide the linking key field in [F_Subform].
Clicking on a name in the list box opens [F_Subform] and displays the
records related to the name you clicked. If you'd rather use a separate
Command Button, attach the code in function lbxMain_Click() to the
Command Button's "On Click" event instead.
[quoted text clipped - 20 lines]