Returning Null value instead of contents of field

From: Royboy (Royboy_at_discussions.microsoft.com)
Date: 02/23/05


Date: Tue, 22 Feb 2005 19:17:01 -0800

The first time I retirieve data from a field the correct contents are
returned but thereafter it returns a Null value.

To replicate the "Feature" create a form with 2 command buttons and add the
following code.

Click Command1 and the correct value sent to the immediate window.
Click command2 and the correct value is sent then a Null.

The only difference between the buttons is the Cursor Location.

What is going on here?

Option Explicit

Private m_Conn As ADODB.Connection
Private m_SQL As String

Private Sub Command1_Click()

Dim rs1 As ADODB.Recordset
    
    Set rs1 = New Recordset
    With rs1
        .ActiveConnection = m_Conn
        .Source = m_SQL
        .CursorType = adOpenForwardOnly
        .LockType = adLockReadOnly
        .CursorLocation = adUseClient
' .CursorLocation = adUseServer
        .Open Options:=(adCmdText)

    End With
    
    
    If Not (rs1.EOF And rs1.BOF) Then
    
        Call PrintResults(rs1)
        Call PrintResults(rs1)
    End If
    
    rs1.Close
    
End Sub

Private Sub Command2_Click()

Dim rs2 As ADODB.Recordset
    
    Set rs2 = New Recordset
    With rs2
        .ActiveConnection = m_Conn
        .Source = m_SQL
        .CursorType = adOpenForwardOnly
        .LockType = adLockReadOnly
' .CursorLocation = adUseClient
        .CursorLocation = adUseServer
        .Open Options:=(adCmdText)

    End With
    
    
    If Not (rs2.EOF And rs2.BOF) Then
    
        Call PrintResults(rs2)
        Call PrintResults(rs2)
    End If
    
    rs2.Close

End Sub

Private Sub PrintResults(ByRef rs As ADODB.Recordset)

    Debug.Print "Description "; rs("Description").Value
    
    
End Sub

Private Sub Form_Load()
    
    
    Set m_Conn = New ADODB.Connection

    
    m_SQL = "Select Description, CategoryID, CategoryName from Categories"
    
    m_Conn.ConnectionString = " Provider=MSDASQL.1;Persist Security
Info=False;DSN=nwind;UID=;DATABASE=Northwind;Trusted_Connection=Yes"
        
    m_Conn.Open
    
    
End Sub

Private Sub Form_Unload(Cancel As Integer)

    m_Conn.Close
End Sub