Access表单中如何将GAME表TeamID关联显示TEAM表球队名称
Solution to Display Team Names Instead of IDs in Access Form Listbox
Got it, let's fix this so your listbox shows actual team names instead of IDs. Here's a step-by-step breakdown:
1. Build the Correct SQL Query
You need to join the TEAM table twice (once for home teams, once for away teams) to pull both names. Here's the full query, with placeholders you'll need to adjust:
SELECT g.GameTime, ht.TeamName AS [Home Team], at.TeamName AS [Away Team] FROM DBO.GAME g INNER JOIN DBO.TEAM ht ON g.HomeTeamID = ht.TeamID INNER JOIN DBO.TEAM at ON g.AwayTeamID = at.TeamID WHERE DateValue(g.GameTime) = Forms!YourFormName!YourDateComboBoxName;
Key Notes:
htandatare aliases for theTEAMtable (home team and away team) to avoid confusion.DateValue(g.GameTime)extracts just the date from yourGameTimefield to match the date selected in your combo box (adjust this ifGameTimeis already a pure date field).- Replace
YourFormNameandYourDateComboBoxNamewith the actual names of your form and date combo box.
2. Configure the Listbox in Your Form
In Access Form Design View:
- Select your listbox, then open the Property Sheet.
- Set Row Source Type to
Table/Query. - Paste the adjusted SQL query into the Row Source field.
- Set Column Count to
3(since we're pulling 3 fields). - Set Column Heads to
Yesto show "GameTime", "Home Team", "Away Team" as headers. - Adjust Column Widths to your preference (e.g.,
1;2;2to make team name columns wider—units are inches/cm based on your Access settings).
3. Refresh the Listbox When the Date Changes
To make the listbox update automatically when the user selects a new date:
- Open the After Update event of your date combo box.
- Add this VBA code:
Me.YourListBoxName.Requery - Replace
YourListBoxNamewith the actual name of your listbox.
That's it! Now when you select a date from the combo box, the listbox will display the game time along with the full home and away team names instead of IDs.
内容的提问来源于stack exchange,提问作者foreff




