Results 1 to 3 of 3

Thread: How to write the code to a command button to paste text?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Posts
    788

    How to write the code to a command button to paste text?

    Dear Friends,

    I have to write code to the command button for the following use.

    I have a command button called "cmdDetails". when I press this button it should enter the following text in a textbox called "txtDetails". The property of this textbox is set to "Multiline".

    The following is the text to be entered automatically in a single textbox (which has the multiline property set as TRUE) when the cmdDetails button is pressed:

    Currency : Dollor
    Conversion : Rs. 45
    Invoice Amount : $ 100
    Invoice Amount : Rs. 4500

    Thanks in advance.

  2. #2
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: How to write the code to a command button to paste text?

    Is this what you are after?
    make sure the textbox height is enough or set the verticle scrollbar to true

    Code:
    Private Sub cmdDetails_Click()
    
    txtdetails.Text = "Currency : Dollor" & vbCrLf & _
                           "Conversion : Rs. 45" & vbCrLf & _
                           "Invoice Amount : $100" & _
                           "Invoice Amount : Rs. 45"
    End Sub
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: How to write the code to a command button to paste text?

    ...or if you want to insert the text use the SelText property instead of the Text property. If you want to add the text to the end of the textbox set the SelStart property to the length of the text in the textbox (see below) before setting the SelText property.
    Code:
    With txtDetails
        .SelStart = Len(.Text)
        .SelText = "Currency: Dollar" & vbCrLf & "Conversion ...." 
    End With

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width