Solved

SelectAll and Copy through Code

Posted on 2000-02-25
4
445 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
Comment Utility
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
Comment Utility
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
Comment Utility
Dedushka, cool!
0
 
LVL 1

Author Comment

by:scottsanpedro
Comment Utility
Dedushka,

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

Thanks very much

Scott
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

772 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

10 Experts available now in Live!

Get 1:1 Help Now