By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,260 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

How to add CR/LF to a forms .value text box

P: 19
I am trying to add the cr/lf characters to a form text box. I have used both text and a memo field that is set for Rich Text. I can add them to a string, display the string in a message box - but when I move the string to the forms field the CR/LF are being stripped out. I do not know how to overcome that. Here is a snippet of code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ParentParcel_DblClick(Cancel As Integer)
  2. 'On Error GoTo EndSub
  3. '
  4. ''''''
  5. '
  6. ''''''
  7. Dim NewParentParcel As String
  8. Dim CurrentParentParcel As String
  9. Dim TempMapBookPage As String
  10. Dim strSQL As String
  11. Dim response As String
  12. '
  13. TempMapBookPage = "'" & MapBookPage & "'"
  14. CurrentParentParcel = ParentParcel
  15. TempMapBookPage = "'37/110'"
  16. 'MsgBox (TempMapBookPage)
  17. strSQL = "SELECT * FROM ParentParcelsTable where MapBookPage=" & TempMapBookPage & "order by ParentParcels"
  18. '
  19. Dim dbs As DAO.Database
  20. Dim rstMapQuery As DAO.Recordset
  21. '
  22. Set dbs = CurrentDb
  23. Set rstMapQuery = dbs.OpenRecordset(strSQL, dbOpenSnapshot)
  24. '
  25. Do Until rstMapQuery.EOF
  26.     If NewParentParcel = "" Then
  27.       NewParentParcel = rstMapQuery.Fields("ParentParcels")
  28.     Else
  29.        NewParentParcel = NewParentParcel & vbCrLf & _
  30.          rstMapQuery.Fields("ParentParcels")
  31.     End If
  32.     response = MsgBox(NewParentParcel, vbYesNo)
  33.     ' after this statement I can see the parcel numbers displayed    
  34.   rstMapQuery.MoveNext
  35. '
  36. Loop
  37. '
  38. EndSub:
  39. '
  40. rstMapQuery.Close
  41. Set rstMapQuery = Nothing
  42. Set dbs = Nothing
  43. '
  44. MsgBox ("final result = " & NewParentParcel)
  45. Forms("RecordedMapsForm").ParentParcel.Value = NewParentParcel
  46. Me.Refresh
  47. '
  48. End Sub
Sep 12 '08 #1
Share this Question
Share on Google+
14 Replies


ADezii
Expert 5K+
P: 8,619
To add a Carriage Return/Line Feed combination to any String:
Expand|Select|Wrap|Line Numbers
  1. strAnyString & vbCrLf
Sep 12 '08 #2

P: 19
Thanks ADezii for the quick reply. Please take a look at line 30. At line 46 where the data goes back to the form - they are stripped out for some reason.
Sep 13 '08 #3

ADezii
Expert 5K+
P: 8,619
Thanks ADezii for the quick reply. Please take a look at line 30. At line 46 where the data goes back to the form - they are stripped out for some reason.
Can't think of any reason why they would be. Instead of vbCrLf, you can use:
Expand|Select|Wrap|Line Numbers
  1. Chr$(13) & Chr$(10)
Sep 13 '08 #4

P: 19
I have used vbNewline and the chr(n) codes as well. They all display correctly in the msgbox at ine 33, but after the statement at line 46 the strings are concatenated without the CR/LF. Maybe there is another work-around?
Sep 13 '08 #5

ADezii
Expert 5K+
P: 8,619
I have used vbNewline and the chr(n) codes as well. They all display correctly in the msgbox at ine 33, but after the statement at line 46 the strings are concatenated without the CR/LF. Maybe there is another work-around?
Type the following into the Debug Window (CTRL+G):
Expand|Select|Wrap|Line Numbers
  1. ? "Herman" & vbCrLf & "Munster"
You should see:
Expand|Select|Wrap|Line Numbers
  1. Herman
  2. Munster
Is this the case?
Sep 13 '08 #6

P: 19
Hello ADezii - yes I see it (without the 1. and 2. of course). It would be nice if I could include a screenshot of the msgbox to show you.
Sep 13 '08 #7

ADezii
Expert 5K+
P: 8,619
Hello ADezii - yes I see it (without the 1. and 2. of course). It would be nice if I could include a screenshot of the msgbox to show you.
You never actually answered Post #6, do you see
Expand|Select|Wrap|Line Numbers
  1. Herman
  2. Munster
when you type ?
Expand|Select|Wrap|Line Numbers
  1. "Herman" & vbCrLf & "Munster"
  2.  
Sep 13 '08 #8

P: 19
Yes - I see it in the Immediate Window as you said. Thanks.
Sep 13 '08 #9

ADezii
Expert 5K+
P: 8,619
Yes - I see it in the Immediate Window as you said. Thanks.
Try the code in a Standard Text Box and see what happens.
Sep 14 '08 #10

P: 19
It works in the standard text box. It seems to work everywhere except at line 46 - where it does not work. There is something the compiler is doing to remove the CR/LF's from the stream before in goes back to the form. The form field from line 46 looks like this:
09-2-03-1-001-008.000 09-2-03-1-001-009.000 09-2-03-1-001-010.001 09-2-03-1-001-010.002

I want it to look like this:

09-2-03-1-001-008.000
09-2-03-1-001-009.000
09-2-03-1-001-010.001
09-2-03-1-001-010.002

And this is what the msgbox displays.
Sep 14 '08 #11

ADezii
Expert 5K+
P: 8,619
It works in the standard text box. It seems to work everywhere except at line 46 - where it does not work. There is something the compiler is doing to remove the CR/LF's from the stream before in goes back to the form. The form field from line 46 looks like this:
09-2-03-1-001-008.000 09-2-03-1-001-009.000 09-2-03-1-001-010.001 09-2-03-1-001-010.002

I want it to look like this:

09-2-03-1-001-008.000
09-2-03-1-001-009.000
09-2-03-1-001-010.001
09-2-03-1-001-010.002

And this is what the msgbox displays.
Would it be possible for you to send me the DB as an E-Mail Attachment? I'm currently on vacation, but the problem is that I am not running Access 2007 but when I get into work next week, I'll be more than happy to have a look at it for you. Kindly let me know one way or the other.
Sep 15 '08 #12

P: 19
Thanks ADezii for the extra nice offer. I would not put you out like that. Maybe, I will continue to experiment for other work-arounds and hit on something. I'll repost if I get a solution. Thanks much.
Sep 15 '08 #13

P: 19
I found a work-around for the problem. You cannot have the field on the form set for Rich Text. I deleted the field from the form. Saved/Closed the form and changed the table field from Memo to Text, size=255. Re-added the field back to the form and re-ran the same procedure. This time it produced the same results as the msgbox had been displaying all along. The Rich Text option must cause the CR/LF to be removed. I hope this helps someone else in the future.
Sep 15 '08 #14

ADezii
Expert 5K+
P: 8,619
I found a work-around for the problem. You cannot have the field on the form set for Rich Text. I deleted the field from the form. Saved/Closed the form and changed the table field from Memo to Text, size=255. Re-added the field back to the form and re-ran the same procedure. This time it produced the same results as the msgbox had been displaying all along. The Rich Text option must cause the CR/LF to be removed. I hope this helps someone else in the future.
Thanks for sharing this information with us.
Sep 15 '08 #15

Post your reply

Sign in to post your reply or Sign up for a free account.