Solved

Array from ADO recordset, then display in a mesaage box

Posted on 2004-08-19
11
187 Views
Last Modified: 2010-04-17
Exactly what the title says....
This is the code I have, but I don't know ow to display the array in a mesage box....

   Set adoMRS2 = New ADODB.Recordset
   With adoMRS2
                  strSql2 = "Select Product_ID from tracking_file Where Product_ID <> '" & strDTID & "' AND field_1 ='" & strSS & "'"

             .Open strSql2, adoMCN2, , , 1
            End With
If Not adoMRS2.EOF Then
arr1 = adoMRS2.GetRows

MSGBOX "These are the results: " & arr1

I would prefer to have each record on a anew line, so I suppose I need to insert &Chr(13) betwen each.
0
Comment
Question by:lexo
  • 3
  • 2
  • 2
  • +3
11 Comments
 
LVL 6

Expert Comment

by:bkthompson2112
ID: 11846344
Hi lexo,

You'll need to loop through arr1 and add each field of each record to a string.
after each record add a vbCrLf.

then use that string in the msgbox.

Be careful, according to msdn: "The maximum length of prompt is approximately 1024 characters, depending on the width of the characters used."
see here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbenlr98/html/vafctMsgBox.asp

maybe a better way to do this would be to loop throught arr1 and use debug.print to send the results to the immediate window.

bkt
0
 
LVL 8

Expert Comment

by:bramsquad
ID: 11846351
'do everything to get your array here

        Dim arr1() As String

        Dim i As Integer, total As String
        For i = 0 To arr1.Length - 1
            total += arr1(i) + vbCrLf
        Next

msgbox( "These results are:" + vbcrlf + vbcrlf + total )

~b

0
 
LVL 8

Expert Comment

by:bramsquad
ID: 11846356
just to note, vbcrlf is the visual basic constant for a carriage return, i know you mentioned Chr(13)
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:lexo
ID: 11846399
it errors at .Length.  I am using a very toned down version of Vb in a macro. I don't think it sees that as a function.
0
 
LVL 8

Expert Comment

by:bramsquad
ID: 11846714
im using .net, prolly why.....try this

For i = 0 To UBound(arr1) - 1

~b
0
 
LVL 3

Expert Comment

by:Stimphy
ID: 11857664
Try this...

Join(Arr1,vbCrLf)


Regaurds,
Dave
0
 
LVL 18

Expert Comment

by:JR2003
ID: 11860230
The GetRows method is used to copy records from a Recordset object into a variant that is a two-dimensional array. The variant array is automatically dimensioned (sized) to fit the requested number of columns and rows. To allow backwards compatibility with earlier versions of ADO, the columns are placed in the first dimension of the array and the rows are placed in the second dimension.

Dim arr1 as Variant
Dim i as Long
Dim j As Long

 Set adoMRS2 = New ADODB.Recordset
   With adoMRS2
               strSql2 = "Select Product_ID from tracking_file Where Product_ID <> '" & strDTID & "' AND field_1 ='" & strSS & "'"

             .Open strSql2, adoMCN2, , , 1
            End With
If Not adoMRS2.EOF Then
arr1 = adoMRS2.GetRows

For i = LBound(arr1, 1) to UBound(arr1, 1)
    sLine = ""
    For j LBound(arr1, 2) to UBound(arr1, 2)
        sLine = sLine & arr1(j, i) & ", "
    Next j
    sLine = Left(sLine, Len(sLine) -2)
    Debug.Print sLine
    MsgBox "Line " & i & " " & sLine
Next i

0
 
LVL 3

Expert Comment

by:Stimphy
ID: 11863845
I think what you are doing now will probably be your best alternative.

Regaurds,
Dave
0
 

Author Comment

by:lexo
ID: 11874894
Ok I got it to work, but didn't use the code provided to me here.  Thank you for your time!!

arr1 is a string.

If Not adoMRS2.EOF Then
Do Until adoMRS2.EOF = True
   arr1=  arr1 & adoMRS2("Loan_ID") & vbCrLf
   adoMRS2.MoveNext
Loop
MsgBox "Results:  " & vbCrLf & arr1
End If
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 12097181
PAQed, with points refunded (500)

CetusMOD
Community Support Moderator
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
advertisement module in core php 4 170
Path to Python 9 129
VbScript to countdown to New Year's Day 6 65
Output in PHP throwing alignment of data off issue 12 43
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question