Solved

SelectAll and Copy through Code

Posted on 2000-02-25
4
456 Views
Last Modified: 2012-08-13
I'm making a reference system for source code. By the user selecting a description in the main form undates showing the code required. I want a button that will selectAll the text in the control and automatically copy to the clipboard..
I've tried  DoCmd.RunCommand acCmdSelectAll but get an error..

Any help??

Scottsanpedro
0
Comment
Question by:scottsanpedro
  • 2
4 Comments
 
LVL 10

Expert Comment

by:paasky
ID: 2557788
Hello scottsanpedro,

This function selects all text of Text1 textbox:

Private Sub B_SelectAll_Click()
    With Text1
        .SetFocus
        If Len(.Value) > 0 Then
             ' select all text
             .SelStart = 1
             .SelLength = Len(Text1)

            ....
            ....

        End If
    End With
End Sub

Regards,
Paasky
0
 
LVL 7

Accepted Solution

by:
Dedushka earned 50 total points
ID: 2557823
scottsanpedro,
to copy text automatically to clipboard you can use this function from Acc2000 Developer Code Librarian:
____________________________
     Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) _
         As Long
      Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) _
         As Long
      Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, _
         ByVal dwBytes As Long) As Long
      Declare Function CloseClipboard Lib "User32" () As Long
      Declare Function OpenClipboard Lib "User32" (ByVal hwnd As Long) _
         As Long
      Declare Function EmptyClipboard Lib "User32" () As Long
      Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, _
         ByVal lpString2 As Any) As Long
      Declare Function SetClipboardData Lib "User32" (ByVal wFormat _
         As Long, ByVal hMem As Long) As Long

      Public Const GHND = &H42
      Public Const CF_TEXT = 1
      Public Const MAXSIZE = 4096



      Function ClipBoard_SetData(MyString As String)
         Dim hGlobalMemory As Long, lpGlobalMemory As Long
         Dim hClipMemory As Long, X As Long

         ' Allocate moveable global memory.
         '-------------------------------------------
         hGlobalMemory = GlobalAlloc(GHND, Len(MyString) + 1)

         ' Lock the block to get a far pointer
         ' to this memory.
         lpGlobalMemory = GlobalLock(hGlobalMemory)

         ' Copy the string to this global memory.
         lpGlobalMemory = lstrcpy(lpGlobalMemory, MyString)

         ' Unlock the memory.
         If GlobalUnlock(hGlobalMemory) <> 0 Then
            MsgBox "Could not unlock memory location. Copy aborted."
            GoTo OutOfHere2
         End If

         ' Open the Clipboard to copy data to.
         If OpenClipboard(0&) = 0 Then
            MsgBox "Could not open the Clipboard. Copy aborted."
            Exit Function
         End If

         ' Clear the Clipboard.
         X = EmptyClipboard()

         ' Copy the data to the Clipboard.
         hClipMemory = SetClipboardData(CF_TEXT, hGlobalMemory)

      OutOfHere2:

         If CloseClipboard() = 0 Then
            MsgBox "Could not close Clipboard."
         End If

         End Function
________________________

Just call it from your button's OnClick event:

ClipBoard_SetData(Me.[txtSourceCode])

Best regards,
Dedushka
0
 
LVL 10

Expert Comment

by:paasky
ID: 2557842
Dedushka, cool!
0
 
LVL 1

Author Comment

by:scottsanpedro
ID: 2557881
Dedushka,

Didn't quite imagine it would be this big but it works perfectly..

Thanks very much

Scott
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

947 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now