Solved

Using debug.print to print horizontal (like crosstab)

Posted on 2011-02-13
6
499 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…

747 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

12 Experts available now in Live!

Get 1:1 Help Now