Solved

Array from ADO recordset, then display in a mesaage box

Posted on 2004-08-19
11
185 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now