Results 1 to 3 of 3

Thread: ADODB Recordset (Easy One)

  1. #1

    Thread Starter
    Fanatic Member skald2k's Avatar
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    535

    ADODB Recordset (Easy One)

    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim results As ADODB.Recordset
    3.    
    4.     Set results = New ADODB.Recordset           ' Create new Recordset
    5.     If Not (results.BOF Or results.EOF) Then
    6.         MsgBox results.Fields.Count
    7.     End If
    8. End Sub

    Why doesn't the above code work? It gives me an run-time error "operation not allowed when object is closed". However if I add a field to the recordset then it works. I need to create an EMPTY recordset for a function. Whats the problem here?
    - If at first you dont succeed, then give up, cause you will never will!

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: ADODB Recordset (Easy One)

    Originally posted by skald2k
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim results As ADODB.Recordset
    3.    
    4.     Set results = New ADODB.Recordset           ' Create new Recordset
    5.     If Not (results.BOF Or results.EOF) Then
    6.         MsgBox results.Fields.Count
    7.     End If
    8. End Sub

    Why doesn't the above code work? It gives me an run-time error "operation not allowed when object is closed". However if I add a field to the recordset then it works. I need to create an EMPTY recordset for a function. Whats the problem here?
    That's because you haven't done

    results.open SQLSTRING

    yet. Have you? When you create your recordset, it is already empty, but .eof and .bof don't count.

    here's an example of how to create an empty recordset with 6 columns (from MSDN I think--copy and paste)


    with results
    .Fields.Append "Column1", adBSTR, 25
    .Fields.Append "Column2", adInteger
    .Fields.Append "Column3", adBSTR, 25
    .Fields.Append "Column4", adVarChar, 25
    .Fields.Append "Column5", adBSTR, 25
    .Fields.Append "Column6", adDBTimeStamp, 25
    end with

  3. #3

    Thread Starter
    Fanatic Member skald2k's Avatar
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    535
    Hmm okay I understand, although VB gives me a stupid "closed" error message.

    I need the recordset to contain no columns though because that will indicate to my client that the SQL string has failed or is incorrect. If there ARE columns appended then it will mean that the SQL string worked but there just isn't any records to be found.
    - If at first you dont succeed, then give up, cause you will never will!

Posting Permissions

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



Click Here to Expand Forum to Full Width