Build a string text from result set
Sub MyFirstConnection4()
Dim myConnection As ADODB.Connection
Dim myRecordset As ADODB.Recordset
Dim strSQL As String
Dim strOutput As String
strSQL = "SELECT FirstName, LastName FROM Employees"
Set myConnection = CurrentProject.Connection
Set myRecordset = New ADODB.Recordset
myRecordset.Open strSQL, myConnection
Do Until myRecordset.EOF
strOutput = strOutput + myRecordset.Fields("FirstName") & " " & _
myRecordset.Fields("LastName") & vbCrLf
myRecordset.MoveNext
Loop
myRecordset.Close
msgBox strOutput
myConnection.Close
Set myConnection = Nothing
Set myRecordset = Nothing
End Sub
Related examples in the same category