Solved

MS Access - forcing a new line in a report text box using Expression Builder

Posted on 2009-05-14
12
1,872 Views
Last Modified: 2013-11-28
I am trying to force a new line in a text box in a report in MS Access.  For example, one of the things I am trying to do is build an address block.  I am a relative neophyte to Access, so I've been using the expression builder.  Things that I've tried so far:

=[Name] & vbcrlf & [Address] & vbcrlf & [Citystatezip]
- MS access adds brackets around the vbcrlf and it shows up as a query prompt when i run the report

=[Name] & "
" & [Address] & "
" & [Citystatezip]
- The carriage returns in the quotes are interpreted as an open square - all on one line.

Any other suggestions?  If this is only possible outside of expression builder, please make your explanation as simple as possible, since I am new!

THank you in advance!
0
Comment
Question by:TechRescue
  • 6
  • 2
  • 2
  • +2
12 Comments
 
LVL 5

Expert Comment

by:DBDevl
ID: 24389639
Use 3 separate text boxes
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24390508
TechRescue,

I agree with DBDevl.
Why not just use 3 textboxes?
I mean, you have three separate fields anyway?

1. =[Name] & vbcrlf & [Address] & vbcrlf & [Citystatezip]
...This will only work in VBA code. (note the keword here is "VB"crlf)
;-)

If you want to use a the same characters in the textbox directly, use:
=[Name] & chr(13) & chr(10) & [Address] & chr(13) & chr(10) & [Citystatezip]

;-)

JeffCoachman
0
 

Author Comment

by:TechRescue
ID: 24390746
I wanted to use one textbox bc I cannot convince my boss that it is possible to have consistent line spacing.  She wants the report to look exactly like Word - no matter how I have formatted the spacing between the text boxes (even showing her with a ruler that they are the same) she will not believe me.  Was trying another way to convince her - running this report in Access would take seconds each time - doing it manually in Word takes hours......

That is my honest answer as to why I was starting this in the first place.....
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.

 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24390835
OK,

So did you try my suggestion of using the ASCI character codes insteado of vbcrlf?
0
 
LVL 3

Expert Comment

by:DK_User
ID: 24391926
I would agree about using 3 seperate textboxes, bc its the easiest and its the Access way. But having said that you could do it like this to please your boss.
Make a 'dummy' Label in the report, and name it 'AddressBlock'. You will probably have to write a little text in it at design time, or Access deletes it again.
Hide your 3 textboxes in the Report so that they dont show up.
In the Report's Load and Page Events you then put this code.
Try to avoid naming your Query field "Name" as it sometimes can confuse Access.
Thats why im naming it PersonName

Private Sub Report_Load()
Me.AddressBlock.Caption = Me.PersonName & vbCrLf & Me.Address & vbCrLf & Me.City
End Sub
 
Private Sub Report_Page()
Me.AddressBlock.Caption = Me.PersonName & vbCrLf & Me.Address & vbCrLf & Me.City
End Sub

Open in new window

0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 125 total points
ID: 24392175
TechRescue,

LOL!

Now with 3 experts suggesting using individual textboxes, I think it should be clear what the consensus is.
;-)
That coupled with the fact that it takes longer to do it "the bosses way"....
;-)

I never met a boss who would rather spend Hours rather than seconds
:-O

Jeff
0
 
LVL 2

Expert Comment

by:Joeyen5
ID: 24394812
Please try one of the following:

A) =[Name] & Chr(13) & Chr(10) & [Address] & Chr(13) & Chr(10) & [Citystatezip]

B) =[Name] & vbCrLf & [Address] & vbCrLf & [Citystatezip]


0
 

Author Comment

by:TechRescue
ID: 24396795
I think I managed to convince the boss to try it - you are all correct - seperate textboxes is by far the best (and how I originally set it up!)

Thank you
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24399130
Joeyen5,

That is what I suggested earlier. (Post 24390508)

The issue is that the asker wanted this in the textbox directly, so vbcrlf was not an option.

;-)

Jeff
0
 
LVL 2

Expert Comment

by:Joeyen5
ID: 24399348
Sorry about that boag2000, I didn't read your whole post.  I saw "3 text boxes" and kept going.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24399391
;-)
No sweat, I do it all the time too.
;-)

Enjoy your weekend.
;-)

Jeff
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24399432
TechRescue,

Thanks, but it would have been fairer to split the points evenly between the three posts that suggested the 3 texbox approach.

Or even more correctly, just give all the points to DBDevl, for being the "First" to post this suggestion.
;-)

Either way, I am OK with it.

Please click the "Request Attention" button in your original post to correct this.

;-)

Jeff
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

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…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

831 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