ASP - Using Function parameter to refer to recordset
asp-classic, vbscript
Solution
The other answers here are similar but ...
Sub DiplayData(rst)
Response.Write rst.Source
End Sub
DisplayData rs1
Note `Sub` not `Function` since no value is returned. Also where you call a procedure as statement rather than as a function whose value you are assigning to a variable, do not enclose the parameters in ( ).
Problem
Sorry if the title is a bit vague. I couldn't think how else to say it! I have a script which retrieves data into 3 different recordsets. They are called rs1, rs2 and rs3. I have quite a large piece of code later on in the script so I have created a function to save save space etc. Within the function I wish to use the information from the recordsets opened earlier. I have tried passing the name of the recordset to the function as follows: ``` Function displayData(recordsetName) response.write(recordsetName.Source) End Function displayData("rs1") ``` However this is trying to show the results from a recordset called recordsetName and as that doesen't exist it is throwing up an error. Somebody told me to use 'ByRef' however this throws up an error saying the the recordset does not exist. How can I use a recorset name passed to a function as a parameter? Thanks