Solved

MS Access  - VBA - Chr(13)  not working

Posted on 2009-03-30
6
3,473 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
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now