Solved

Using debug.print to print horizontal (like crosstab)

Posted on 2011-02-13
6
524 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 - 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

856 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