This example demonstrates the GetString method.
Assume you are debugging a data access problem and want a quick, simple way of printing the current contents of a small Recordset.
Public Sub Main()
GetStringX
End Sub
Public Sub GetStringX()
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim varOutput As Variant
Dim strQuery As String
Dim strPrompt As String
Set cnn = New ADODB.Connection
Set rst = New ADODB.Recordset
strPrompt = "Enter a state (CA, IN, KS, MD, MI, OR, TN, UT): "
strState = Trim(InputBox(strPrompt, "GetString Example"))
strQuery = "SELECT au_fname, au_lname, address, city FROM Authors " & _
"WHERE state = '" & strState & "'"
cnn.Open "DSN=Pubs;Provider=MSDASQL; uid=sa;pwd=;"
rst.Open strQuery, cnn, adOpenStatic, adLockReadOnly, adCmdText
If rst.RecordCount > 0 Then
'Use all defaults: get all rows, TAB column delimiter, CARRIAGE RETURN
'row delimiter, empty-string null delimiter
varOutput = rst.GetString(adClipString)
Debug.Print "State = '" & strState & "'"
Debug.Print "Name Address City" & vbCr
Debug.Print varOutput
Else
Debug.Print "No rows found for state = '" & strState & "'" & vbCr
End If
rst.Close
cnn.Close
End Sub