Solved

Using debug.print to print horizontal (like crosstab)

Posted on 2011-02-13
6
539 Views
Last Modified: 2012-05-11
Experts,

I'm using the code below to loop through a record on a form. However, instead of debug.print displaying the information vertical, I'd like for it to display horizontal (like crosstab)l.
 
For example...

Normal debug.print
1
2
3

Horizontal debug.print
1 2 3

Thank you,
James

Dim rst As dao.Recordset
        Dim strReport As String
        
        Set rst = Me.RecordsetClone
        
        With rst
            .MoveFirst
            Do While Not .EOF                   
                    
                    strString = rst!ReportInfo
                    
                    Debug.Print strString
                    
                .MoveNext
                
            Loop
        End With

Open in new window

0
Comment
Question by:jdallain
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 500 total points
ID: 34883876
Like this ...

            Do While Not .EOF                  
                   
                    strString = strString & " " &  rst!ReportInfo
                   
                    '   Debug.Print strString
                   
                .MoveNext
               
            Loop
     
           Debug.Print strString

mx
0
 
LVL 75
ID: 34883880

How about just this:

        Dim strReport As String
               
        With Me.RecordsetClone
            .MoveFirst
            Do While Not .EOF                  
                   
                    strString = strString & " " &  rst!ReportInfo
                   
                    '   Debug.Print strString
                   
                .MoveNext
               
            Loop
     
           Debug.Print strString

        End With
0
 
LVL 11

Expert Comment

by:RgGray3
ID: 34883894
Method 1, place a comma after the data being printed
Try the following in the immediate window

Dim x As Integer

    For x = 1 To 10
        Debug.Print x,
    Next
   
End Sub

this may not be suitable depening on what the data is and its size and consistency as the comma acts like a Tab

or you can Move the Debug.print outside the loop and build a string where you currently have the debug.print

Not knowing the data behind ReportInfo this may or may not suit your needs

You Lets say that report info is 15 characters in size...  you could define a var as string 18 and when you debug.print it it would guarentee 3 characters between values


0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Closing Comment

by:jdallain
ID: 34883900
Thank you very much! I probably should have been able to figure that out :)
0
 
LVL 19

Expert Comment

by:Richard Daneke
ID: 34883910
You cannot unprint a debug.print, so I think you would need to extend the string on each repeat:
1
1 2
1 2 3
Then, the code attached may work.
Dim rst As dao.Recordset 
        Dim strReport As String 
         
        Set rst = Me.RecordsetClone 
	
         
        With rst 
            .MoveFirst 
            Do While Not .EOF                    
                    ' we build the string by tacking on the next values
                    strString = strString & " " & rst!ReportInfo 
                     
                    Debug.Print strString 
                     
                .MoveNext 
                 
            Loop 
        End With

Open in new window

0
 
LVL 75
ID: 34883915
You are welcome. That's why we are here ... just in case you can't ... at the moment :-)

mx
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

691 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