neillovell
Programmer
Hi all,
I'm having a problem looping through tables with a recordset - the Microsoft examples are not very clear to me. I'll explain what I want to do.
I have a table of players (PlayerTable) which has the ID number, name, and total points. I then have a table for each individual team - e.g. SomeTeamA, SomeTeamB etc.
I'm trying to create a recordset for PlayerTable and one for SomeTeamA, and perform some kind of loop where SomeTeamA's first player is looked up in PlayerTable and the total points added to SomeTeamA's totalpoints column. Then the second player is looked up, etc. etc.
I can then adapt the code for SomeTeamB, and the others.
Below I've just got an SQL string outputted to a messagebox (as a test) but the entire thing fails on the .OpenRecordset line. Can anyone help me out?
Private Sub UpdateTeamsButton_Click()
Dim DatabaseConnection As ADODB.Connection
Dim SQL As String
Set DatabaseConnection = Application.CurrentProject.Connection
' Error handling procedure.
If (Err) Then
Error_Handler:
MsgBox Err.Description, vbCritical
End If
Dim Counter As Integer
Dim CurrentPlayerTotalPoints As Integer
Dim TeamMemberRecordset As Recordset
Dim RecordLoop As Recordset
With DatabaseConnection
' Open the RecordSet for PlayerTable
Set TeamMemberRecordset = .OpenRecordset("PlayerTable"
For Each rstLoop In .Recordsets
With rstLoop
SQL = "SELECT TotalPoints FROM PlayerTable WHERE ID=123"
MsgBox SQL
End With
Next rstLoop
TeamMemberRecordset.Close
End With
End Sub
I'm having a problem looping through tables with a recordset - the Microsoft examples are not very clear to me. I'll explain what I want to do.
I have a table of players (PlayerTable) which has the ID number, name, and total points. I then have a table for each individual team - e.g. SomeTeamA, SomeTeamB etc.
I'm trying to create a recordset for PlayerTable and one for SomeTeamA, and perform some kind of loop where SomeTeamA's first player is looked up in PlayerTable and the total points added to SomeTeamA's totalpoints column. Then the second player is looked up, etc. etc.
I can then adapt the code for SomeTeamB, and the others.
Below I've just got an SQL string outputted to a messagebox (as a test) but the entire thing fails on the .OpenRecordset line. Can anyone help me out?
Private Sub UpdateTeamsButton_Click()
Dim DatabaseConnection As ADODB.Connection
Dim SQL As String
Set DatabaseConnection = Application.CurrentProject.Connection
' Error handling procedure.
If (Err) Then
Error_Handler:
MsgBox Err.Description, vbCritical
End If
Dim Counter As Integer
Dim CurrentPlayerTotalPoints As Integer
Dim TeamMemberRecordset As Recordset
Dim RecordLoop As Recordset
With DatabaseConnection
' Open the RecordSet for PlayerTable
Set TeamMemberRecordset = .OpenRecordset("PlayerTable"
For Each rstLoop In .Recordsets
With rstLoop
SQL = "SELECT TotalPoints FROM PlayerTable WHERE ID=123"
MsgBox SQL
End With
Next rstLoop
TeamMemberRecordset.Close
End With
End Sub