Results 1 to 5 of 5

Thread: Code to copy textbox to clipboard

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2004
    Location
    Surrey, UK
    Posts
    163

    Code to copy textbox to clipboard

    Is there some simple coding i can use to copy the contents of textbox to the clipboard????

  2. #2
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: Code to copy textbox to clipboard

    What database are you using... if your talking about access you may be able to do it via macros.
    Last edited by <ABX; May 27th, 2005 at 06:18 AM. Reason: Overtired....
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2004
    Location
    Surrey, UK
    Posts
    163

    Re: Code to copy textbox to clipboard

    I'm using MSAccess 2003.

    I've kinda cheated, but then it works....

    VB Code:
    1. Dim copypasteUpdater As String
    2.  
    3. copypasteUpdater = [ContractorName].Value & vbCrLf
    4.  
    5. If [Address].Value <> "" Then copypasteUpdater = copypasteUpdater + [Address].Value & vbCrLf
    6. If [Town].Value <> "" Then copypasteUpdater = copypasteUpdater + [Town].Value & vbCrLf
    7. If [County].Value <> "" Then copypasteUpdater = copypasteUpdater + [County].Value & vbCrLf
    8. If [PostCode].Value <> "" Then copypasteUpdater = copypasteUpdater + [PostCode].Value
    9.    
    10.     [txtCopyPastebox].Value = copypasteUpdater
    11.  
    12. txtCopyPastebox.SetFocus
    13. DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70

    I made txtCopyPastebox textbox 0cm wide and very small, and then put it beside my copy button.

    would have preferred to copy copypasteUpdater string direct to clipboard, but nevermind!

  4. #4
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Code to copy textbox to clipboard

    This example uses the SetText method to copy text from a text box to the Clipboard. To try this example, paste the code into the Declarations section of a form with a text box named Text1, and then press F5 and click the form.

    VB Code:
    1. Private Sub Form_Click ()
    2.    Const CF_TEXT = 1   ' Define bitmap format.
    3.    Dim I, Msg, Temp   ' Declare variables.
    4.    On Error Resume Next   ' Set up error handling.
    5.    Msg = "Type anything you like into the text box below."
    6.    Text1.Text = InputBox(Msg)   ' Get text from user.
    7.    Msg = "Choose OK to copy the contents of the text box "
    8.    Msg = Msg & "to the Clipboard."
    9.    MsgBox Msg   ' Display message.
    10.    ClipBoard.Clear   ' Clear Clipboard.
    11.    Clipboard.SetText Text1.Text   ' Put text on Clipboard.
    12.    If Clipboard.GetFormat(CF_TEXT) Then
    13.       Text1.Text = ""   ' Clear the text box.
    14.       Msg = "The text is now on the Clipboard. Choose OK "
    15.       Msg = Msg & "to copy the text from the Clipboard back "
    16.       Msg = Msg & "to the text box."
    17.       MsgBox Msg   ' Display message.
    18.       Temp = Clipboard.GetText(CF_TEXT)   ' Get Clipboard text.
    19.       For I = Len(Temp) To 1 Step -1   ' Reverse the text.
    20.          Text1.Text = Text1.Text & Mid(Temp, I, 1)  
    21.       Next I
    22.    Else
    23.       Msg = "There is no text on the Clipboard."
    24.       MsgBox Msg   ' Display error message.
    25.    End If
    26. End Sub
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2004
    Location
    Surrey, UK
    Posts
    163

    Re: Code to copy textbox to clipboard

    I'm using MSAccess 2003.

    the "Clipboard" is not a recognised object in Access.

    if I remove the

    VB Code:
    1. On Error Resume Next   ' Set up error handling.

    line then I get an error saying "Run-time Error 424, Object Required."

    at the

    VB Code:
    1. ClipBoard.Clear   ' Clear Clipboard.

    Line.

    Is there a way of making the clipboard work???

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