[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Add a new line with Visual Basic using Chr(10)

Posted on 2008-11-10
5
Medium Priority
?
1,905 Views
Last Modified: 2013-11-28
I have a very strange problem. I want to add a text to a memo-field in Microsoft Access 2003 using Visual Basic. I have always used Chr(10) without problems. But this time it is just overlooked!? I use DAO to get the text I want and then add Chr(10) and the new text. Should be strait forward. But the new text ends up next to the old text.  I tried copying the text into an editor and then there was a lineshift! Why does it not show in the memofield? Obviously the lineshift is there.

Thank you for all help!

Code:
    Dim vText As String, rs As DAO.Recordset, vDesc As String, SQL As String
    vText = Chr(10) & vPartnrOld & "." & vRevOld & " has been changed to " & vPartnrMod & "." & vRevMod & "-" & vRevDesc
    SQL = "SELECT tbl" & vTbl & "Changes.[Revision Description] FROM tbl" & vTbl & "Changes WHERE (((tbl" & vTbl & "Changes.Partnr)='" & vPartnrPro & "') AND ((tbl" & vTbl & "Changes.Rev)='" & vRevPro & "'));"
    Set rs = CurrentDb.OpenRecordset(SQL, dbOpenDynaset)
    If Not (rs.EOF And rs.BOF) Then
        vDesc = rs![Revision Description]
        vDesc = vDesc & LineChange & vText
        rs.Edit
        rs![Revision Description] = vDesc
        rs.Update
    End If
0
Comment
Question by:hke72
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 22920801
i dont see anythign wrong but maybe you can try to move that Chr(10)  like below...

could you try it?


    Dim vText As String, rs As DAO.Recordset, vDesc As String, SQL As String
    vText =  vPartnrOld & "." & vRevOld & " has been changed to " & vPartnrMod & "." & vRevMod & "-" & vRevDesc
    SQL = "SELECT tbl" & vTbl & "Changes.[Revision Description] FROM tbl" & vTbl & "Changes WHERE (((tbl" & vTbl & "Changes.Partnr)='" & vPartnrPro & "') AND ((tbl" & vTbl & "Changes.Rev)='" & vRevPro & "'));"
    Set rs = CurrentDb.OpenRecordset(SQL, dbOpenDynaset)
    If Not (rs.EOF And rs.BOF) Then
        vDesc = rs![Revision Description]
        vDesc = vDesc & LineChange & Chr(10) &  vText
        rs.Edit
        rs![Revision Description] = vDesc
        rs.Update
    End If

Open in new window

0
 
LVL 1

Author Comment

by:hke72
ID: 22920841
I have already tried that. But as I said the lineshift is in the text (at least if I copy it to Word), but does not change line in my memo-textbox.
I have tried looking at the properties for the field in the form, but have not found anything.
Other ideas?
0
 
LVL 1

Author Comment

by:hke72
ID: 22920868
I also tested copying the text into Word and then copying it back. Then it was OK. There must be something about the textcoding.
Anyone?
0
 
LVL 15

Accepted Solution

by:
Haris Djulic earned 1000 total points
ID: 22920882
can you try char(13) or combination of the 10 and 13

   * Chr(10) returns a linefeed character
    * Chr(13) returns a carriage return character
    * The two-character string Chr(13) & Chr(10) returns a Windows newline
0
 
LVL 1

Author Comment

by:hke72
ID: 22920931
Sorry, same result!
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

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

If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
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 …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

873 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