Solved

SelectAll and Copy through Code

Posted on 2000-02-25
4
479 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

730 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