Solved

MS Access  - VBA - Chr(13)  not working

Posted on 2009-03-30
6
3,622 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 200 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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 300 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

696 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