473,386 Members | 1,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

display formatting (new lines, tabs etc) in VBA Access

8
Hello,

I am using access 07 and have some VBA code which puts some text into a memo field for me. It gets the text from various columns of a table.

Currently it looks like the below:

phil - hire - advanced
jonathan - lessons - beginner
claire - lift pass - local area

etc

Does anyone know of a good resource for info on code for formatting the text? So far I've discovered vbCrLf, that's it! What I'd ideally want is

phil hire advanced
jonathan lessons beginner
claire lift pass local area

In other words how to line up the text into columns and also if there are any features I could use here (e.g. the option to line up to the right hand side of the words or to the left hand side?).

This will be a template email for billing guests so I'm just trying to work out how to make it look good. It needs to stay just as text for the way I'll be emailing it.

Any ideas on where to look to find out what's possible and what the code is? I've found the microsoft help files a whole pile of help again after ages of searching.....

many thanks,

Phil.
Sep 24 '08 #1
6 4569
pteare
8
hello again!

Sorry that's not come out as I meant! on the what I want list I was looking for it to be in neat columns, that's all.

many thanks!

Phil.
Sep 24 '08 #2
NeoPa
32,556 Expert Mod 16PB
What format are you using for the email (HTML, RTF, Plain text)?
Sep 25 '08 #3
ADezii
8,834 Expert 8TB
  1. It's not that easy a Task, but perhaps it is also too close to my bedtime. The following code will precisely position your 3 Strings into 3 perfectly aligned Columns in a Text Box (txtMemoField) Bound to a MEMO Field. The Keys to this code working effectively are:
    • Use a Fixed Width Font for the Text Box, Courier New works nicely.
    • Use of the Space$() Function to accurately position each Column.
    • Use of the Split() Function to place the Elements of each String into an Array.
  2. I'm too tired right now, so I'll simply Post the code and what the subsequent Output will look like in the Text Box.
  3. Any questions, please feel free to ask.
Expand|Select|Wrap|Line Numbers
  1. 'Adjust the Constants to manipulate the Space between Columns
  2. Const intSpacer1 As Integer = 20    'Equalize between Cols 1 and 2
  3. Const intSpacer2 As Integer = 24    'Equalize between Cols 2 and 3
  4. ...
  5. Dim strMemo As String
  6. Dim astrString(2) As String         'Declare an Array of Strings
  7. Dim intCounter As Integer
  8. Dim varString As Variant            'Array to hold each of the 3 Strings
  9. ...
  10. astrString(0) = "phil hire advanced"
  11. astrString(1) = "jonathan lessons beginner"
  12. astrString(2) = "claire lift pass local area"
  13. ...
  14. For intCounter = 0 To 2         'Array of 3 Strings
  15. ..varString = Split(astrString(intCounter), " ")     'Split Elements into another Array
  16. ..strMemo = strMemo & varString(0) & Space$(intSpacer1 - Len(varString(0))) & varString(1) & _
  17.                       ..Space$(intSpacer1 - Len(varString(1))) & varString(2) & vbCrLf
  18. Next
  19. ...
  20. Me![txtMemoField] = strMemo
OUTPUT:
phil.............hire............advanced
jonathan.....lessons.....beginner
claire..........lift..............pass

P.S. - Kindly ignore my Dot Spacers(...), this new format is killing me.
Sep 25 '08 #4
pteare
8
thanks that's great.

If I understand your code right then what it's doing is counting the length of each word / phrase, then adding on the appropriate number of spaces to make the total of phrase-and-trailing-spaces to be always the same number. thanks for the tip on courier as well. That makes perfect sense, thanks very much. I'll get stuck into that.

I'm sending the email out in plain text at the moment, as that works best with my email system as that needs to be all online (as I use different computers in different locations. I had a brief look at outlook but it seems a pain when I need two different computers in two different places looking at the same thing).

Thanks again guys, I should be good on that from now on......

Phil.
Sep 25 '08 #5
NeoPa
32,556 Expert Mod 16PB
That's great Phil :)

For basic text I would have suggested formatting the text using spaces. ADezii has even provided some code to illustrate the concept.

This clearly displays best when a non-proportional font is used for the client, but you'll have no control over that I'm afraid :(
Sep 25 '08 #6
mshmyob
904 Expert 512MB
Since you are using AC2007 you can set your memo to RTF rather than plain text. AC2007 RTF is really HTML so you can just populate your Memo text with HTML code as follows:

Assuming you have a command button and a memo field on your form called txtMemo.

In the OnClick event of the button populate your memo field with 3 columns and 3 rows alligned:

Expand|Select|Wrap|Line Numbers
  1. Dim txtMessage As String
  2. Dim txtMemoHTML As String
  3.     txtMessage = "column 1 row 1     column 2 row 1     column 3 row 1"
  4.     txtMessage = txtMessage & "<BR> column 1 row 2     column 2 row 2     column 3 row 2"
  5.     txtMessage = txtMessage & "<BR> column 1 row 3     column 2 row 3     column 3 row 2"
  6.     txtMemoHTML = "<pre style=""font-family: Verdana, Arial, sans serif;""" & ">"
  7.     txtMemoHTML = txtMemoHTML & txtMessage
  8.     txtMemoHTML = txtMemoHTML & "</pre>"
  9.     Me.txtMemo = txtMemoHTML
  10.  
Here I have used the HTML preformatted tag and set the font to a fixed width font (that is the key). You would also use the previous code to determine length of strings.

I have tried to set tables but I have never gotten it to work. Maybe AC2007 RTF doesn't support the table tag (although no error is displayed).

cheers,
Sep 25 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: Mat | last post by:
<div id="container"> <div id="main"> <div id="header"> <p class="Address">123 Fake Street, </p> <p class="City">Crazy City, </p> <p class="Province">Ontario </p> <p class="PostalCode">H0H...
7
by: Kayle | last post by:
For preservation of indentation when moving the C source file from Windows to Linux machine, what is the advice to format the code. Should the code formatted using spaces instead of tabs? When...
42
by: Eric Gunnerson [MS] | last post by:
You may download the new specification at the C# Developer Center (http://msdn.microsoft.com/vcsharp/language). There is a discussion forum for the C# language on that same page. If you don't...
0
by: Lasse Vågsæther Karlsen | last post by:
I was wondering if someone knew about a control for .NET that allows me to display log messages from an application while it is running. The following things are necessary: - word-wrap -...
13
by: KMiller | last post by:
I would like to control entry into one or more of the tabs > I have set up on my Tab control based on set rules. Does > anyone know how to grey-out the text so that a user will > see that they do...
25
by: mdh | last post by:
Hi Group, Not looking for an answer, but more of an explanation. Thinking back to those heady days when you had the time to do them, may I ask this. Exercise 1-22 asks for a program to "fold"...
11
by: tg989 | last post by:
Okay, here goes. Continuous forms... possibly the best feature of access. The only downside is this: the only way to have a conditional evaluation run on each record invididually is by...
10
by: afromanam | last post by:
Regards, Please help What I'm trying to do is this: (and I can't use reports since I must export to Excel) I export some queries to different tabs in an excel workbook I then loop through...
10
by: sara | last post by:
Hi - I have a report that is 14 columnar sub-reports (Line up: Position- holders in each of our 14 locations - Manager, Assistant Manager, Receiving, Office, etc). I output directly to PDF...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.