HomeGrowth
Technical User
The function below works fine…
Function LoopTheList()
Dim strContactName As String, strContactList As String
Const strQueryName = "qry(2 )PA_7DayAlert_List"
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb ' Open pointer to current database
Set rs = db.OpenRecordset(strQueryName) ' Open recordset on saved query
rs.MoveFirst
Do Until rs.EOF
strContactName = Nz(rs![Responsible contact], "")
strContactList = strContactList & ";" & strContactName
rs.MoveNext
Loop
MsgBox Mid(strContactList, 2)
rs.Close
Set rs = Nothing
Set db = Nothing
End Function
Now I would like to call this function from anywhere and provide a different Query name each time for it to loop through. The call function is
Call LoopTheList (“qry(2 )PA_7DayAlert_List “)
This returns error…However, it works if you pass a table name instead of a query. What is wrong?
Function LoopTheList(strQueryName as String)
Dim strContactName As String, strContactList As String
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb ' Open pointer to current database
Set rs = db.OpenRecordset(strQueryName) ' Open recordset on saved query
rs.MoveFirst
Do Until rs.EOF
strContactName = Nz(rs![Responsible contact], "")
strContactList = strContactList & ";" & strContactName
rs.MoveNext
Loop
MsgBox Mid(strContactList, 2)
rs.Close
Set rs = Nothing
Set db = Nothing
End Function
Function LoopTheList()
Dim strContactName As String, strContactList As String
Const strQueryName = "qry(2 )PA_7DayAlert_List"
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb ' Open pointer to current database
Set rs = db.OpenRecordset(strQueryName) ' Open recordset on saved query
rs.MoveFirst
Do Until rs.EOF
strContactName = Nz(rs![Responsible contact], "")
strContactList = strContactList & ";" & strContactName
rs.MoveNext
Loop
MsgBox Mid(strContactList, 2)
rs.Close
Set rs = Nothing
Set db = Nothing
End Function
Now I would like to call this function from anywhere and provide a different Query name each time for it to loop through. The call function is
Call LoopTheList (“qry(2 )PA_7DayAlert_List “)
This returns error…However, it works if you pass a table name instead of a query. What is wrong?
Function LoopTheList(strQueryName as String)
Dim strContactName As String, strContactList As String
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb ' Open pointer to current database
Set rs = db.OpenRecordset(strQueryName) ' Open recordset on saved query
rs.MoveFirst
Do Until rs.EOF
strContactName = Nz(rs![Responsible contact], "")
strContactList = strContactList & ";" & strContactName
rs.MoveNext
Loop
MsgBox Mid(strContactList, 2)
rs.Close
Set rs = Nothing
Set db = Nothing
End Function