Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check all fields of the recordset from ADO query?

Tags:

vba

ado

I would like to see if there is a command to show the whole record(row) at once. By now I only find method to show individual columns. I am using a ADO connection to the ms access's mdb. Thanks. By the way, I don't know how can I print a message in MS Access's VB form.......does vb provide a console to show that? Debug.Print don't give me anything, I only success with MsgBox...

   With cmdCommand
    .ActiveConnection = conConnection
    .CommandText = "SELECT * from tableA"
    .CommandType = adCmdText
   End With

   With rstRecordSet
    .CursorType = adOpenStatic
    .CursorLocation = adUseClient
    .LockType = adLockReadOnly
    .Open cmdCommand
   End With

   If rstRecordSet.EOF = False Then
        rstRecordSet.MoveFirst
        Do

            MsgBox rstRecordSet.Fields(0) & " " & rstRecordSet.Fields(1)

            rstRecordSet.MoveNext
        Loop Until rstRecordSet.EOF = True
   End If
like image 780
lamwaiman1988 Avatar asked Mar 23 '11 07:03

lamwaiman1988


People also ask

What are different types of Recordset available in Ado?

Recordset objects can support two types of updating: immediate and batched. In immediate updating, all changes to data are written immediately to the underlying data source once you call the Update method.

Which methods is used to open ADO Recordset?

The default cursor for an ADO Recordset is a forward-only, read-only cursor located on the server. Using the Open method on a Recordset object opens a cursor that represents records from a base table, the results of a query, or a previously saved Recordset.

Which cursor type in ADO can move to any record in Recordset?

Static cursor - Provides a static copy of a recordset for you to use to find data or generate reports. Additions, changes, or deletions by other users will not be visible. This is the only type of cursor allowed when you open a client-side Recordset object.


1 Answers

First off, Debug.Print prints to the Immediate Window in the VB[A] Editor. If it's not showing, press Ctrl-G.

Second, there is no single command to show the whole record, you'll have to assemble it the way that Xavinou does in his (her?) answer. Here's the VB syntax, ignoring recordset creation & EOF check (Note that I've declared the variables--you are using Option Explicit, yes?):

Dim fld As Field
Dim msg As String

    For Each fld In rstRecordSet.Fields
        msg = msg & fld.Value & "|"
    Next

Debug.Print msg    'or MsgBox msg 

I think the pipe ("|") makes a better separator than a space, since it's less likely to occur in your data.

like image 101
RolandTumble Avatar answered Oct 23 '22 12:10

RolandTumble