You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

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:

  • ht and at are aliases for the TEAM table (home team and away team) to avoid confusion.
  • DateValue(g.GameTime) extracts just the date from your GameTime field to match the date selected in your combo box (adjust this if GameTime is already a pure date field).
  • Replace YourFormName and YourDateComboBoxName with 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 Yes to show "GameTime", "Home Team", "Away Team" as headers.
  • Adjust Column Widths to your preference (e.g., 1;2;2 to 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 YourListBoxName with 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

火山引擎 最新活动