Hi, I'm writing a procedure which has to make multiple queries to the same table multiple times. I'm opening, closing and using set <var>=nothing with each use.
I get an error <Compile error: Duplicate declaration in current scope.) the second time I try and open a connection to to perform my second query. (Code at bottom of posting)
any help would be appreciated? Should I be ReDimensioning the variables?
Thanks.. Mark
'Define DAO sql strings
Dim sql As String
Dim rs As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb()
'Define SQL statement to query tblMatches for correct match
'Using tblMatches.MatchId vs. combo5.value
sql = "Select * from tblMatches " & _
" WHERE MatchId=" & Combo5.Value & ";"
'Execute SQL Statement
Set rs = db.OpenRecordset(sql, dbOpenDynaset)
'Assign recordset fields to variables
'Home/Away Team
mHomeTeam = rs("HomeTeam")
mAwayTeam = rs("AwayTeam")
...... more code
'close record set connection and set to null
rs.Close
db.Close
Set db = Nothing
------Second Query----------
'Begin logic to update player statistics
'Set 1 Game 1
'Define DAO sql strings
Dim sql As String ---------error occurs here--------
Dim rs As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb()
'Define SQL statement to query tblPlayer Stats for Away Player
'Using Set 1 Game 1 variable vs. tblPlayerStats (Away Player)
sql = "Select * from tblPlayerStats WHERE PlayerAway='" & mS401APlayerAway & _
"' AND PlayerTeam='" & mAwayTeam & "';"
'Execute SQL Statement
Set rs = db.OpenRecordset(sql, dbOpenDynaset)
'close record set connection and set to null
rs.Close
db.Close
Set db = Nothing
Set sql = Nothing
I get an error <Compile error: Duplicate declaration in current scope.) the second time I try and open a connection to to perform my second query. (Code at bottom of posting)
any help would be appreciated? Should I be ReDimensioning the variables?
Thanks.. Mark
'Define DAO sql strings
Dim sql As String
Dim rs As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb()
'Define SQL statement to query tblMatches for correct match
'Using tblMatches.MatchId vs. combo5.value
sql = "Select * from tblMatches " & _
" WHERE MatchId=" & Combo5.Value & ";"
'Execute SQL Statement
Set rs = db.OpenRecordset(sql, dbOpenDynaset)
'Assign recordset fields to variables
'Home/Away Team
mHomeTeam = rs("HomeTeam")
mAwayTeam = rs("AwayTeam")
...... more code
'close record set connection and set to null
rs.Close
db.Close
Set db = Nothing
------Second Query----------
'Begin logic to update player statistics
'Set 1 Game 1
'Define DAO sql strings
Dim sql As String ---------error occurs here--------
Dim rs As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb()
'Define SQL statement to query tblPlayer Stats for Away Player
'Using Set 1 Game 1 variable vs. tblPlayerStats (Away Player)
sql = "Select * from tblPlayerStats WHERE PlayerAway='" & mS401APlayerAway & _
"' AND PlayerTeam='" & mAwayTeam & "';"
'Execute SQL Statement
Set rs = db.OpenRecordset(sql, dbOpenDynaset)
'close record set connection and set to null
rs.Close
db.Close
Set db = Nothing
Set sql = Nothing