boblovesyousomuch
Programmer
I am trying to open an sql statement that the vb code will loop through and add the ids to a string. However I can't even open the query. The query works because I use it to populate the rowsource of a combo box.
It won't open the recordset.
If possible as well could you tell me how to do this but by calling a stored procedure with parameters?
Code is:
Dim SQLAgentByDept As String
Dim db As Database
Dim rs As Recordset
SQLAgentByDept = "SELECT [tblAgentList]![A_Forename] & ' ' & [tblAgentList]![A_Surname] " & _
"AS A_Fullname, tblAgentList.A_ID FROM tblAgentList INNER JOIN tblTeamList ON " & _
"tblAgentList.A_TeamID = tblTeamList.T_ID WHERE (((tblAgentList.A_ID)<>[tblTeamList]![T_Leader]) " & _
"AND ((tblTeamList.T_Department)=[Forms]![FrmCallSummary]![Combo_Dept]));"
Me!Combo_Agent.RowSource = SQLAgentByDept
Set db = CurrentDb
Set rs = db.OpenRecordset(SQLAgentByDept)
With rs
While Not .EOF
AgentString = AgentString & "'" & rs("A_ID"
& "',"
.MoveNext
Wend
.Close
End With
AgentString = Left(AgentString, Len(AgentString) - 1)
End Code
Any help greatly appreciated.
Carl
It won't open the recordset.
If possible as well could you tell me how to do this but by calling a stored procedure with parameters?
Code is:
Dim SQLAgentByDept As String
Dim db As Database
Dim rs As Recordset
SQLAgentByDept = "SELECT [tblAgentList]![A_Forename] & ' ' & [tblAgentList]![A_Surname] " & _
"AS A_Fullname, tblAgentList.A_ID FROM tblAgentList INNER JOIN tblTeamList ON " & _
"tblAgentList.A_TeamID = tblTeamList.T_ID WHERE (((tblAgentList.A_ID)<>[tblTeamList]![T_Leader]) " & _
"AND ((tblTeamList.T_Department)=[Forms]![FrmCallSummary]![Combo_Dept]));"
Me!Combo_Agent.RowSource = SQLAgentByDept
Set db = CurrentDb
Set rs = db.OpenRecordset(SQLAgentByDept)
With rs
While Not .EOF
AgentString = AgentString & "'" & rs("A_ID"
.MoveNext
Wend
.Close
End With
AgentString = Left(AgentString, Len(AgentString) - 1)
End Code
Any help greatly appreciated.
Carl