Solved

Using debug.print to print horizontal (like crosstab)

Posted on 2011-02-13
6
517 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
6 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

Author Closing Comment

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

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

785 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