7

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
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
lamwaiman1988
  • 3,729
  • 15
  • 55
  • 87

3 Answers3

13

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.

RolandTumble
  • 4,633
  • 3
  • 32
  • 37
  • 1
    +1 NB if you want to quickly inspect the contents of an entire recordset then you can dump the whole recordset on to an Excel worksheet using the `CopyFromRecordset` method of an Excel range object - see http://msdn.microsoft.com/en-us/library/bb223288%28v=office.12%29.aspx – barrowc Mar 24 '11 at 00:13
  • You can also get it with View | Immediate Window... or Customize your Toolbar with a button for it. – RolandTumble Mar 24 '11 at 18:18
  • Odd, but for me, I could not put `As Field` or `As String` there. Had to leave it off or I'd get an error: `Expected end of statement`. Worked otherwise. Kudos! – vapcguy Jul 20 '18 at 21:48
2

For the output console, I don't know (since I don't know VB), but for showing the whole record at once, you can use a foreach loop on rstRecordSet.Fields.

In C#, I would write it like :

string msg = "";
foreach (Field f in rstRecordSet.Fields)
{
    msg += f.Value + " ";
}
MessageBox.Show(msg);

Now, you just have to find the VB syntax...

BryanJ
  • 8,485
  • 1
  • 42
  • 61
Xavinou
  • 802
  • 1
  • 6
  • 18
0

Instead of building your own string, piece by piece, you can use the GetString method of the Recordset object:

Debug.Print records.GetString(adClipString, 1)

An unfortunate side effect of this method is that it seems to remove the record from the record set.

Big McLargeHuge
  • 14,841
  • 10
  • 80
  • 108