[AccessD] 64bit and the Clipboard.

Gustav Brock gustav at cactus.dk
Mon Jul 18 02:28:40 CDT 2022


Hi Stuart

Thanks. Never considered that as a method.

I have managed using a textbox with its height set to 0 (zero) and this simple code:

Me!TextForClipboard.Value = TextToCopy
Me!TextForClipboard.SetFocus
DoCmd.RunCommand acCmdCopy
Me!SomeOtherControl.SetFocus

It requires, of course, an open form, but normally you will have that.

However, having textboxes to hold variables is an Access version 1.x ”feature” which you will want to leave behind.

/gustav

Fra: Stuart McLachlan<mailto:stuart at lexacorp.com.pg>
Sendt: 18. juli 2022 08:43
Til: Access Developers discussion and problem solving<mailto:accessd at databaseadvisors.com>
Emne: [AccessD] 64bit and the Clipboard.

There are a number of VBA functions on the intertubes for getting/setting strings on the
Clipboard. They use Global memory and memory copies with API functions.  UNfortunately
none of them seem to work with 64bit Office no matter how you tweak with PtrSafe, LongPtr
etc.

I finally came across a function that uses a totally different approach that works perfectly in
my testing. - and it's much simpler too :)
Courtesy of: ExcelHero.com (Daniel Ferry)

I tweaked it a bit to suit my style for the code below :)

( I no longer have a 32bit Office installation, can someone using it try the function and report
back? )


Function Clipboard(Optional sText As String) As String
'PURPOSE: Set/Get  Clipboard text.  Omitting sText Gets the clipboard text
Dim x As Variant    'variant required for 64bit
Dim oHTMLFile As Object
  x = sText
  Set oHTMLFile = CreateObject("htmlfile")
  With oHTMLFile
    With .parentWindow.clipboardData
      Select Case Len(sText)
        Case 0 'No vriable passed, Read from the clipboard
            Clipboard = .GetData("text")
        Case Else 'Write to the clipboard
            .setData "text", x
      End Select
    End With
  End With
  Set oHTMLFile = Nothing
End Function



More information about the AccessD mailing list