Microsoft Access - On Mouse Double Click Past Text From Clipboard

  • Thread starter Daniel.Laurens.Daddy
  • Start date
D

Daniel.Laurens.Daddy

Hello,

Is there any way to do the following -

When a user double clicks (on mouse double click) a field in a form it
paste's the text from the Windows clipboard?

I have a program that will send text to the clipboard and overwrite it
each time a new scan is made, so the user could just double mouse
click in the form instead of typing in all of the information, but I
can't figure out how to get the text into Access on mouse double
click...

THANK YOU!!
 
G

Graham Mandeno

Hi Daniel

The code below contains functions to read from and write to the clipboard.
Create a new module, copy the code and paste it into the module, then save
it as mdlClipboard or some such.

Then use the ClipBoard_GetText function in the DblClick event procedure for
your textbox:

Private Sub MyTextBox_DblClick( Cancel as integer)
MyTextBox = ClipBoard_GetText
End Sub
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


============== start code ==============
Option Explicit

Private Declare Function GlobalUnlock _
Lib "kernel32" ( _
ByVal hMem As Long _
) As Long

Private Declare Function GlobalLock _
Lib "kernel32" ( _
ByVal hMem As Long _
) As Long

Private Declare Function GlobalAlloc _
Lib "kernel32" ( _
ByVal wFlags As Long, _
ByVal dwBytes As Long _
) As Long

Private Declare Function GlobalSize _
Lib "kernel32" ( _
ByVal hMem As Long _
) As Long

Private Declare Function lstrcpy _
Lib "kernel32" ( _
ByVal lpString1 As Any, _
ByVal lpString2 As Any _
) As Long

Private Declare Function CloseClipboard _
Lib "user32" ( _
) As Long

Private Declare Function OpenClipboard _
Lib "user32" ( _
ByVal hWnd As Long _
) As Long

Private Declare Function EmptyClipboard _
Lib "user32" ( _
) As Long

Private Declare Function GetClipboardData _
Lib "user32" ( _
ByVal wFormat As Long _
) As Long

Private Declare Function SetClipboardData _
Lib "user32" ( _
ByVal wFormat As Long, _
ByVal hMem As Long _
) As Long

Private Const GHND = &H42
Private Const CF_TEXT = 1

Public Function ClipBoard_SetText(strCopyString As String) As Boolean
Dim hGlobalMemory As Long
Dim lpGlobalMemory As Long
Dim hClipMemory As Long

' Allocate moveable global memory.
hGlobalMemory = GlobalAlloc(GHND, Len(strCopyString) + 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, strCopyString)

' Unlock the memory and then copy to the clipboard
If GlobalUnlock(hGlobalMemory) = 0 Then
If OpenClipboard(0&) <> 0 Then
Call EmptyClipboard
hClipMemory = SetClipboardData(CF_TEXT, hGlobalMemory)
ClipBoard_SetText = CBool(CloseClipboard)
End If
End If
End Function

Public Function ClipBoard_GetText() As String
Dim hClipMemory As Long
Dim lpClipMemory As Long
Dim strCBText As String
Dim lngSize As Long
If OpenClipboard(0&) <> 0 Then
' Obtain the handle to the global memory
' block that is referencing the text.
hClipMemory = GetClipboardData(CF_TEXT)
If hClipMemory <> 0 Then
' Lock Clipboard memory so we can reference
' the actual data string.
lpClipMemory = GlobalLock(hClipMemory)
If lpClipMemory <> 0 Then
lngSize = GlobalSize(lpClipMemory)
strCBText = Space$(lngSize)
Call lstrcpy(strCBText, lpClipMemory)
Call GlobalUnlock(hClipMemory)
' Peel off the null terminating character.
strCBText = Left(strCBText, InStr(strCBText, vbNullChar) - 1)
End If
End If
Call CloseClipboard
End If
ClipBoard_GetText = strCBText
End Function

Public Function Clipboard_CopyOLE(obj As Object)
Dim hGlobalMemory As Long, lpGlobalMemory As Long
Dim hClipMemory As Long

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

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

'Need to copy the object to the memory here
lpGlobalMemory = lstrcpy(lpGlobalMemory, obj)

' Unlock the memory and then copy to the clipboard
If GlobalUnlock(hGlobalMemory) = 0 Then
If OpenClipboard(0&) <> 0 Then
Call EmptyClipboard
hClipMemory = SetClipboardData(CF_TEXT, hGlobalMemory)
Clipboard_CopyOLE = CBool(CloseClipboard)
End If
End If
End Function
============= end code ================
 
P

Piet Linden

On Aug 13, 3:42 pm, (e-mail address removed) wrote:

you'd call the

Copy the code from this link into a new module.
http://www.mvps.org/access/api/api0049.htm

then in the double-click event of your control (textbox), add the
following code:

Private Sub txtCheckThis_DblClick(Cancel As Integer)
Me.txtCheckThis = ClipBoard_GetText
End Sub

Replace "txtCheckThis" with the name of your textbox on your form.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top