Table Displayed in Text Box? (5 Viewers)

TheSearcher

Registered User.
Local time
Today, 16:02
Joined
Jul 21, 2011
Messages
349
I have a listbox whose rowsource is a table consisting of two columns. Works great.
However, the user wants the data to be displayed as text in a text box so that they can copy/paste into a Word document.
I already wrote the code to loop through the table and write the table's rows into a text box using vbCrLf for line breaks. However, it looks ugly because the data is not uniform. I would like the data to look like it does in the table with distinctive and well defined columns.
Is there a way to display a table in a text box?
Any suggestions will be greatly appreciated.

TS
 
Not easily.

You can use a non-proportional font; that will make it easier to line things up.
You can experiment with Rich Text setting for the textbox (and underlying field, if any) and format the list using HTML.

Me, I would use 1 small textbox, and only display the text from the selected row in the listbox. ControlSource of this textbox:
=myListbox.Column(1)
 
Copy/paste to Word as normal paragraph or as a table?

I do this - build string for display in textbox on report. Use String() to "pad" with spaces to align as columns. And set textbox with non-proportional font.
I just tested copy/paste to Word. Have to change font and line spacing in Word.

Then I tested Rich Text formatted text. Format carries over with copy/paste.

Rich Text in Access is a limited set of HTML tags. I tried tags for building a tabular structure and Access ignores them.
 
Last edited:
use datasheet or continuous form bound to your table.
 
was about to suggest the same - use a datasheet subform rather than a listbox

alternatively you can use the space function (rather than the string function). So assuming your data looks something like
aaabbb
cccccceeee
1234456
ABDEV + 23ffff

determine the maximum width the first column needs to be - say 10 chars, add a further 5 -=15 spaces

then loop through your listbox recordset with code something like

Code:
with mylstBox.recordset
    .movefirst
    while not .eof
       txtbox=txtbox & .fields(0) & space(15-len(.fields(0))) & .fields(1) & vbcrlf
       .movenext
    wend
End With

as suggested, better to use a non-proportional font
 
Showing the data in the listbox is better than trying to make it look good in a textbox. Add a button that concatenates the data into a tabular format. Use tabs to separate the fields and crlf to separate the rows. Then the button can copy to the clipboard but the user still has to manually paste to word. OR, you actually automate word and create the word document automatically. It depends on if the document is custom or if it is a template with variables. If it is the latter, you can automate the whole thing.

Just in case you're interested, here is a very rudimentary sample of automating word. The sample explains how you can expand the concept to use variable bookmark names. The sample only uses hard-coded names so has limited usefulness.
 
Nevermind. I used a non-proportional font and it solved my problem. Thanks so much for your help!
 

Users who are viewing this thread

Back
Top Bottom