Force of New Line Using Button (1 Viewer)

pedropangelinan

New member
Local time
Today, 05:14
Joined
Jan 13, 2021
Messages
9
So I may be dumb for asking, but I am working on make a log using a single text box within a form. I would like there to be button where it pastes the most recent item in my clipboard in the text box each time I press the button. However, I have no idea if it is even possible to place a command in vba to force a newline in the textbox. I have everything basically created to paste but I am just missing that piece to force a new line. Any ideas?
 

Minty

AWF VIP
Local time
Today, 10:14
Joined
Jul 26, 2013
Messages
10,369
Add a VbCrLf to your string.

PasteValue = VbCrLf & YourString
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:14
Joined
Oct 29, 2018
Messages
21,467
Is it for long text/memo field with rich text format?
 

pedropangelinan

New member
Local time
Today, 05:14
Joined
Jan 13, 2021
Messages
9
Add a VbCrLf to your string.

PasteValue = VbCrLf & YourString
So this is what I have:

Private Sub Toggle70_Click()
Me.textbox.SetFocus
DoCmd.RunCommand acCmdPaste
End Sub

The thing is that I am unsure how to add the VbCrLf into this. I have tried many ways but each time doesn't work. I might be doing it wrong, can you give an example?
 

pedropangelinan

New member
Local time
Today, 05:14
Joined
Jan 13, 2021
Messages
9
Is it for long text/memo field with rich text format?
Yes, it is a Long Text with Rich Text format. I am trying to move away from basically having to click in the textbox and pressing enter to go to a newline. I am creating this to log in a single text all actions being done in the access sheet but for now using a button to paste the most recent item in the clipboard and adding a new line.
 

Minty

AWF VIP
Local time
Today, 10:14
Joined
Jul 26, 2013
Messages
10,369
Take the contents after the paste and add a line feed - something like

Me.textbox.SetFocus
DoCmd.RunCommand acCmdPaste
Me.txtbox = Me.txtbox & VbCrLf
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:14
Joined
Oct 29, 2018
Messages
21,467
Yes, it is a Long Text with Rich Text format. I am trying to move away from basically having to click in the textbox and pressing enter to go to a newline. I am creating this to log in a single text all actions being done in the access sheet but for now using a button to paste the most recent item in the clipboard and adding a new line.
For a Long Text with Rich Text Format, you may have to use "<br>" instead of vbCrLf.
 

pedropangelinan

New member
Local time
Today, 05:14
Joined
Jan 13, 2021
Messages
9
Take the contents after the paste and add a line feed - something like

Me.textbox.SetFocus
DoCmd.RunCommand acCmdPaste
Me.txtbox = Me.txtbox & VbCrLf
End Sub
So for some reason, it forces my access database to completely close. It does paste, but it doesn't add the new line. I even tried to switch it around and it doesn't work
 

Minty

AWF VIP
Local time
Today, 10:14
Joined
Jul 26, 2013
Messages
10,369
As @theDBguy suggested you may need to use <p> to force a paragraph into the text as it is rich text?
 

pedropangelinan

New member
Local time
Today, 05:14
Joined
Jan 13, 2021
Messages
9
As @theDBguy suggested you may need to use <p> to force a paragraph into the text as it is rich text?
Gotcha, so I replaced it but now it's just not pasting. It's kinda weird but I've switched it around and the only function that happens it the new line but not the paste.
 

Minty

AWF VIP
Local time
Today, 10:14
Joined
Jul 26, 2013
Messages
10,369
Try doing it as two different operations, just to prove a point.

Create a command button and after the paste is successful try using the button to add the new line.
 

pedropangelinan

New member
Local time
Today, 05:14
Joined
Jan 13, 2021
Messages
9
Try doing it as two different operations, just to prove a point.

Create a command button and after the paste is successful try using the button to add the new line.
Did it and it creates the new line but does not paste. I've tried to paste but it doesn't paste into the new line.
 

Minty

AWF VIP
Local time
Today, 10:14
Joined
Jul 26, 2013
Messages
10,369
Let me clarify - you should now have 2 command buttons.
One simply does the paste and works?
One simply adds a new Line to the existing text and doesn't work?

If that's the case please post the code for the two buttons?
 

pedropangelinan

New member
Local time
Today, 05:14
Joined
Jan 13, 2021
Messages
9
Let me clarify - you should now have 2 command buttons.
One simply does the paste and works?
One simply adds a new Line to the existing text and doesn't work?

If that's the case please post the code for the two buttons?
So one the button for the new line which is just the code below creates the new line:
Me.Text50 = Me.Text50 & vbCrLf
The button to paste (the code below) is the one that should paste, however it pastes on the first line only. Not the new line that was created.
Me.Text50.SetFocus
DoCmd.RunCommand acCmdPaste
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:14
Joined
Oct 29, 2018
Messages
21,467
So one the button for the new line which is just the code below creates the new line:
Me.Text50 = Me.Text50 & vbCrLf
The button to paste (the code below) is the one that should paste, however it pastes on the first line only. Not the new line that was created.
Me.Text50.SetFocus
DoCmd.RunCommand acCmdPaste
Looks like you may have totally missed my previous comment.
 

Minty

AWF VIP
Local time
Today, 10:14
Joined
Jul 26, 2013
Messages
10,369
Apart from missing out on the suggestion to use <br> e.g.

Me.Text50 = Me.Text50 & "<br>"

I think this whole thing would be much easier if we assigned the clipboard contents to a string variable. Have a look here;

SQL:
'---------------------------------------------------------------------------------------
' Procedure : Clipboard_GetText
' Author    : Daniel Pineault, CARDA Consultants Inc.
' Website   : http://www.cardaconsultants.com
' Purpose   : Retrieve the clipboard value
' Copyright : The following is release as Attribution-ShareAlike 4.0 International
'             (CC BY-SA 4.0) - https://creativecommons.org/licenses/by-sa/4.0/
' Req'd Refs: Late Binding  -> none required
'
' Usage:
' ~~~~~~
' Debug.Print Clipboard_GetText
' sClipboardValue = Clipboard_GetText
'
' Revision History:
' Rev       Date(yyyy-mm-dd)        Description
' **************************************************************************************
' 1         2020-11-25              Initial Public Release
'---------------------------------------------------------------------------------------
Public Function Clipboard_GetText() As String
    On Error GoTo Error_Handler
 
    With CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
        .GetFromClipboard
        Clipboard_GetText = .GetText
    End With
 
Error_Handler_Exit:
    On Error Resume Next
    Exit Function
 
Error_Handler:
    MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
           "Error Number: " & Err.Number & vbCrLf & _
           "Error Source: Clipboard_GetText" & vbCrLf & _
           "Error Description: " & Err.Description & _
           Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
           , vbOKOnly + vbCritical, "An Error has Occurred!"
    Resume Error_Handler_Exit
End Function

Put this code into a Module. Save the module as mod_Clipboard

Now in your button code do the following.
SQL:
Dim sClipB as String

sClipB = "<br>"   ' Add a line break '
' Now add the clipboard contents after the break'
sClipB = sClipB  & Clipboard_GetText
' Now assign the whole lot to the existing textbox string'
Me.Text50 = Me.Text50 & sClipB
 

pedropangelinan

New member
Local time
Today, 05:14
Joined
Jan 13, 2021
Messages
9
I had to change the "<vb>" to vbCrLf because I made the mistake thinking it was rich text, but it works.
Thank you.
 

Users who are viewing this thread

Top Bottom