grantwilliams
Programmer
Hi,
I have a form (MainForm), which has a subform (MainFrame) consisting of two list boxes (YearList and Team) and a Command Button.
At the moment, the user selects a Year and the Team list box will show a list of teams that played that year. The user selects a team and presses the Command Button.
I have the Command Button opening a Form in Datasheet View, using the following code to create the RecordSource:
Private Sub Form_Load()
Dim Year, Team, Receipt, DBIDSQL, NameSQL, TeamSQL, PlayerReceiptSQL
Year = Forms!MainForm!MainFrame.Form.YearList
Team = Forms!MainForm!MainFrame.Form.Team
Receipt = Forms!MainForm!MainFrame.Form.YearList & "_Receipt"
DBIDSQL = "SELECT DISTINCT PlayerHistory.RegisterID, " & _
"[PlayerDetails].[Surname], [PlayerDetails].[GivenName] As [GivenName], " &_
"[PlayerHistory].[" & Year & "] As [Team], [PlayerReceipt].[" & _
& Receipt & "] As [Receipt] FROM ([PlayerDetails] INNER JOIN [PlayerHistory]" & _
" ON [PlayerDetails].[RegisterID] = [PlayerHistory].[RegisterID])" & _
" INNER JOIN [PlayerReceipt] ON ([PlayerReceipt].[RegisterID]" & _
" = [PlayerDetails].[RegisterID]) AND ([PlayerHistory].[RegisterID]" & _
" = [PlayerReceipt].[RegisterID]) WHERE [PlayerHistory].[" & Year & "]" & _
" = '" & Team & "';"
Me.RecordSource = DBIDSQL
End Sub
This produces the right data in the datasheet, but I want to be able to edit the fields, for instance, the team field once team grading is completed.
I guess that there's something wrong in the way I'm referencing the three tables, perhaps in using the INNER JOIN statement.
Can anyone help me with this? I've been working on this database for 3 weeks and my brain is now officially fried. I've spent 8 hours on this one problem so far and was able to produce the datasheet 6 hours ago!
Is there any way of doing this using a standard SQL query, given that I'm using the Year list box to choose which column of the PlayerHistory table to query on?
Thanks!
Grant.
I have a form (MainForm), which has a subform (MainFrame) consisting of two list boxes (YearList and Team) and a Command Button.
At the moment, the user selects a Year and the Team list box will show a list of teams that played that year. The user selects a team and presses the Command Button.
I have the Command Button opening a Form in Datasheet View, using the following code to create the RecordSource:
Private Sub Form_Load()
Dim Year, Team, Receipt, DBIDSQL, NameSQL, TeamSQL, PlayerReceiptSQL
Year = Forms!MainForm!MainFrame.Form.YearList
Team = Forms!MainForm!MainFrame.Form.Team
Receipt = Forms!MainForm!MainFrame.Form.YearList & "_Receipt"
DBIDSQL = "SELECT DISTINCT PlayerHistory.RegisterID, " & _
"[PlayerDetails].[Surname], [PlayerDetails].[GivenName] As [GivenName], " &_
"[PlayerHistory].[" & Year & "] As [Team], [PlayerReceipt].[" & _
& Receipt & "] As [Receipt] FROM ([PlayerDetails] INNER JOIN [PlayerHistory]" & _
" ON [PlayerDetails].[RegisterID] = [PlayerHistory].[RegisterID])" & _
" INNER JOIN [PlayerReceipt] ON ([PlayerReceipt].[RegisterID]" & _
" = [PlayerDetails].[RegisterID]) AND ([PlayerHistory].[RegisterID]" & _
" = [PlayerReceipt].[RegisterID]) WHERE [PlayerHistory].[" & Year & "]" & _
" = '" & Team & "';"
Me.RecordSource = DBIDSQL
End Sub
This produces the right data in the datasheet, but I want to be able to edit the fields, for instance, the team field once team grading is completed.
I guess that there's something wrong in the way I'm referencing the three tables, perhaps in using the INNER JOIN statement.
Can anyone help me with this? I've been working on this database for 3 weeks and my brain is now officially fried. I've spent 8 hours on this one problem so far and was able to produce the datasheet 6 hours ago!
Is there any way of doing this using a standard SQL query, given that I'm using the Year list box to choose which column of the PlayerHistory table to query on?
Thanks!
Grant.