adding a carriage return to a field in access

Robert Suttner 1 Reputation point
2021-07-14T18:43:06.567+00:00

Good afternoon. It's been years since i've used access and now using access 2016.

i have a table with a number of fields.
I've added a query to select a few of the fields i want to add to a form.

The field i'm focusing on is called description. The data in that field looks like this
Who: the cat what: wants to cross the road where: at the house when: everyday why: because it's a cat.

when i add that field to a form i would like to display the text like:

Who: the cat

What: wants to cross the road

Where: at the house

When: everyday

Why: because it's a cat

any help would be greatly appreciated.

Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
849 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. DBG 2,301 Reputation points
    2021-07-14T19:42:19.427+00:00

    Hi. The carriage return in Access (in Windows OS, really) consists of two characters: CR + LF.

    To add them to your data, you would concatenate Chr(13) & Chr(10) into it. However, I am not sure how to apply that idea to your data, because you seem to want to insert the carriage returns in certain places.

    If you're using a Long Text field, there may be another option, which is to use the Rich Text Format, so the user can insert the carriage returns easily during data entry.

    Just a thought...

    0 comments No comments

  2. David Catherman 0 Reputation points
    2023-12-20T17:42:07.14+00:00

    I found a property for forms that controls what happens on the enter key (set it to new line in field) but I still have an issue with the datasheet mode. It does not let me enter a return but goes to the next field. Any clues?

    0 comments No comments

  3. Albert Kallal 5,226 Reputation points
    2023-12-20T19:54:00.6266667+00:00

    What I suggest is that you create a so called continues form (multiple items form). Then, as you note, you can change/set the enter key behavior to cause a new line.

    So, say a form like this:

    conenterk

    So, while the above is "not quite" like a data sheet, adopting a continues form (multiple items form), then you can control the behavour of the enter key for that text box.

    And bonus points is that the above type of form allows check box, combo box, and near unlimited customizing. Datasheets can be fun, quick, but for advanced customizing, then try a continues items form like above (use the wizard to help you create the basic form, and then in design mode you can clean up and customize the results for your needs.

    0 comments No comments

  4. Ken Sheridan 2,756 Reputation points
    2023-12-20T22:24:25.9266667+00:00
    The following is a quick and dirty function which will parse the string expression into a series of substrings separated by a double carriage return/line feed as in your example:
    
    Public Function ParseString(ByVal strIn As String)
    
        Dim strQuestion As String
        Dim strAnswer As String
        Dim strLine As String
        
        Do Until InStr(strIn, ":") = 0
            strQuestion = Left(strIn, InStr(strIn, ":"))
            strIn = Mid(strIn, Len(strQuestion) + 1)
            strAnswer = Left(strIn, InStr(strIn, ":"))
            strAnswer = RTrim(Left(strAnswer, InStrRev(strAnswer, " ")))
            If Len(strAnswer) = 0 Then
                strAnswer = Mid(strIn, InStr(strIn, ":") + 1)
            End If
            strLine = strLine & vbNewLine & vbNewLine & UCase(Left(strQuestion, 1)) & Mid(strQuestion, 2) & strAnswer
            strIn = Mid(strIn, Len(strAnswer) + 2)
        Loop
        
        ParseString = Mid(strLine, 5)
        
    End Function
    
    You can see how it works in the Immediate window:
    
    strTest = "Who: the cat what: wants to cross the road where: at the house when: everyday why: because it's a cat."
    
    ? ParseString(strTest)
    Who: the cat
    
    What: wants to cross the road
    
    Where: at the house
    
    When: everyday
    
    Why: because it's a cat.
    
    The function does of course assume a uniformity of formatting of the string expression passed into it.
    
    
    0 comments No comments