?
Solved

MS Access  - VBA - Chr(13)  not working

Posted on 2009-03-30
6
Medium Priority
?
3,732 Views
Last Modified: 2013-12-20
I'm trying to put a hard return using Chr(13) into 3 different places
a Listbox.Caption,
a text field in a table
and a memo field in a table

Using VBA in MS Access 2007

In the listbox I get a square box with a ? mark in it
In the text and memo fields I get a space (ascii 32)

Other Chr functions are working, like Chr(34)

A simple sample is like this
sText = sText + Chr(13) + sLicense

I can manually put the return in the text\/memo fields by by pressing Crtl+Return so I know the field accepts this character

While this is probably stupid/easy I cant find any reason its not working, everything says it should work, and points are high because I am in a hurry




0
Comment
Question by:allan1956
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 47

Assisted Solution

by:Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs) earned 600 total points
ID: 24025788
Try using vbCrLf instead....

    sText = sText & vbCrLf & sLicense

And use the ampersand (&) for string concatenations.

Wayne
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24026117
you might need to include a chr$(10) with the chr$(13) but what webtubbs should do the same and save you from using chr


0
 

Author Comment

by:allan1956
ID: 24026246
Hi, thanks
Well partial success.  Using & didn't change anything

Using vbvbCrLf  did make the label.Caption work, the return/line breaks are there

However,still no luck on the database text/memo fields.  Which was more important

If I cut/paste the text from the memo filed into a hex editor, I see that Ascii 32 is whats there - a space

This happens when using Chr(10) as well


0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 28

Expert Comment

by:TextReport
ID: 24026335
Hi allan1956, in VBA if you are using + then if any of your variables are NULL then your result will be NULL, normally you would use & rather than + as

Null + "A" = Null
Null & "A" = "A"

Chr(13) & Chr(10) is the same as vbCrLf and I use this all over the place including populating text and memo fields. It is not possible to use vbCrLf in a query and you have to use Chr(13) & Chr(10) and if has to be CR LF and not LF CR.

Below is a test from a question yesterday that shows it works in Access 2007 on the query, this is then value in one field combining several fields.

Cheers, Andrew
ISSUES: 1
STAFFING: 2
SCHEDULE: 3
SCOPE: 4
FINANCIALS: 5
RISKS: 6

Open in new window

0
 
LVL 28

Accepted Solution

by:
TextReport earned 900 total points
ID: 24026387
Found it, can you check the Text Format of the Memo Field, it will be set to Rich Text. For Rich Text fields you need to use "</P>" instead of Chr(13) & Chr(10).
Cheers, Andrew
0
 

Author Comment

by:allan1956
ID: 24032975
ok, that was it, using html in the memo field- i used a <br /> when witting to the and it worked.  I  cut/paste the date into a hex editor and found that writing out <br /> actually stores as 0D0A or Chr(13)Chr(10)

Strange and not all that intuitive.  

So vbCrLf for the label caption and <br /> for the memo field
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

762 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