Returning a recordset from a function

Results 1 to 3 of 3

Thread: Returning a recordset from a function

  1. #1
    Ken S Guest

    Default Returning a recordset from a function

    Hi,<BR><BR>I&#039;ve created a function that accepts a querystring, executes it, and sends back the recordset. However, I want to check if the recordset returned anything in the subroutine that calls the function so I can reuse the function without having a generic error message.<BR><BR>Here is the function:<BR><BR>Function GetData (strSQL) <BR><BR> &#039;-- Connect to DB<BR><BR> %&#062; &#060;!-- #include file = "connect_db.asp" --&#062; &#060;%<BR> <BR> &#039;-- Prepare and execute the query<BR> <BR> Set objCmd = server.CreateObject ("adodb.command")<BR> Set objRS = server.CreateObject ("adodb.recordset")<BR> Set objCmd.ActiveConnection = Conn<BR> objCmd.CommandText = strSQL<BR> objCmd.CommandType = 1<BR> <BR> &#039;-- Results returned in a recordset<BR> <BR> Set objRS = objCmd.Execute<BR> <BR> Set GetData = objRS<BR> <BR>End Function <BR><BR>and here is the portion of the Main subroutine that calls the function:<BR><BR>strSQL = "select * from some_table"<BR><BR>objRS = GetData (strSQL)<BR> <BR>If not objRS.EOF then<BR> <BR> &#039; Do whatever you need to with the recordset <BR>Else <BR> <BR> &#039; Display whatever error message would be appropriate for the query that was run.<BR> <BR>End if<BR><BR>The problem is that I get an error where I use the .EOF property in my subroutine to determine if the recordset came back with anything. I get the following message:<BR><BR>Object doesn&#039;t support this property or method: &#039;objRS.EOF&#039;<BR><BR>Can anyone help me out with this?<BR><BR>Thanks!

  2. #2
    Join Date
    Dec 1969

    Default RE: Returning a recordset from a function

    Hey!<BR> In ur code change "objRS = GetData (strSQL)" line as <BR><BR>Set objRS = GetData (strSQL) <BR>

  3. #3
    Ken S Guest

    Default RE: Returning a recordset from a function

    Agnes -<BR><BR>Thanks a lot! Big time rookie mistake from a big time rookie! :)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts