Solved

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

Posted on 2009-05-14
12
1,658 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
 
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
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

 
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

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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