by

How to consume a RecordSet in VBA

This is a simple example of how to consume a recordset in VBA.
It relies on the ExecQuery method explained in the related snippet.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/64485/How-to-consume-a-RecordSet-in-VBA?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
Dim rd As ADODB.Recordset Dim sql As String, res As String res = "" sql = "SELECT Something FROM MyTable WHERE Year=2014" Set rd = ExecQuery(sql) If (rd Is Nothing) Then GoTo ErrorQuery While Not rd.EOF res = res + rd("Something") rd.MoveNext Wend MsgBox(res) Exit ErrorQuery: MsgBox("Something wrong here")

Other Steps and Solutions

If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus