Using Clipboard object in Access 97 
Author Message
 Using Clipboard object in Access 97

I am creating a app in Access 97 in which I would like to use the clipboard
object for cutting & pasting text, I inserted the VB objects & procedures
type library into the references for the database, but whenever I refer to
the clipboard object, I get the error message "ActiveX component can't
create object." The help for this error suggests that something is not
installed correctly, however, the same code works fine in VB. Any
suggestions?

Rohn




Sun, 20 Aug 2000 03:00:00 GMT  
 Using Clipboard object in Access 97

Hi,

Sorry but since I don't know VB, I won't be able to tell you why the code
works in one place but not in another.  However, I've used the following set
of functions before w/o any problems. See if you can use these instead.
Public Const GHND = &H42
Public Const MAXSIZE = 4096
Public Const CF_TEXT = 1
Private Const CF_ANSIONLY = &H400&
Private Const CF_APPLY = &H200&
Private Const CF_BITMAP = 2
Private Const CF_DIB = 8
Private Const CF_DIF = 5
Private Const CF_DSPBITMAP = &H82
Private Const CF_DSPENHMETAFILE = &H8E
Private Const CF_DSPMETAFILEPICT = &H83
Private Const CF_DSPTEXT = &H81
Private Const CF_EFFECTS = &H100&
Private Const CF_ENABLEHOOK = &H8&
Private Const CF_ENABLETEMPLATE = &H10&
Private Const CF_ENABLETEMPLATEHANDLE = &H20&
Private Const CF_ENHMETAFILE = 14
Private Const CF_FIXEDPITCHONLY = &H4000&
Private Const CF_FORCEFONTEXIST = &H10000
Private Const CF_GDIOBJFIRST = &H300
Private Const CF_GDIOBJLAST = &H3FF
Private Const CF_HDROP = 15
Private Const CF_INITTOLOGFONTSTRUCT = &H40&
Private Const CF_LIMITSIZE = &H2000&
Private Const CF_LOCALE = 16
Private Const CF_MAX = 17
Private Const CF_METAFILEPICT = 3
Private Const CF_NOFACESEL = &H80000
Private Const CF_NOSCRIPTSEL = &H800000
Private Const CF_NOSIMULATIONS = &H1000&
Private Const CF_NOSIZESEL = &H200000
Private Const CF_NOSTYLESEL = &H100000
Private Const CF_NOVECTORFONTS = &H800&
Private Const CF_NOOEMFONTS = CF_NOVECTORFONTS
Private Const CF_NOVERTFONTS = &H1000000
Private Const CF_OEMTEXT = 7
Private Const CF_OWNERDISPLAY = &H80
Private Const CF_PALETTE = 9
Private Const CF_PENDATA = 10
Private Const CF_PRINTERFONTS = &H2
Private Const CF_PRIVATEFIRST = &H200
Private Const CF_PRIVATELAST = &H2FF
Private Const CF_RIFF = 11
Private Const CF_SCALABLEONLY = &H20000
Private Const CF_SCREENFONTS = &H1
Private Const CF_BOTH = (CF_SCREENFONTS Or CF_PRINTERFONTS)
Private Const CF_SCRIPTSONLY = CF_ANSIONLY
Private Const CF_SELECTSCRIPT = &H400000
Private Const CF_SHOWHELP = &H4&
Private Const CF_SYLK = 4
Private Const CF_TIFF = 6
Private Const CF_TTONLY = &H40000
Private Const CF_UNICODETEXT = 13
Private Const CF_USESTYLE = &H80&
Private Const CF_WAVE = 12
Private Const CF_WYSIWYG = &H8000

Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags&, ByVal _
    dwBytes As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem 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 GlobalUnlock Lib "kernel32" (ByVal hMem As Long) _
    As Long
Private Declare Function OpenClipboard Lib "user32" (ByVal Hwnd As Long) _
    As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As _
    Long) As Long
Private Declare Function EmptyClipboard Lib "user32" () As Long
Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat _
    As Long, ByVal hMem As Long) As Long

Function fapiGetClipboard()
    Dim hClipMemory As Long
    Dim lpClipMemory As Long
    Dim MyString As String
    Dim RetVal As Long

    If OpenClipboard(0&) = 0 Then
        MsgBox "Cannot open Clipboard. Another app. may have it open"
        Exit Function
    End If

    ' Obtain the handle to the global memory
    ' block that is referencing the text.
    hClipMemory = GetClipboardData(CF_TEXT)
    If IsNull(hClipMemory) Then
        MsgBox "Could not allocate memory"
        GoTo OutOfHere
    End If

    ' Lock Clipboard memory so we can reference
    ' the actual data string.
    lpClipMemory = GlobalLock(hClipMemory)

    If Not IsNull(lpClipMemory) Then
        MyString = Space$(MAXSIZE)
        RetVal = lstrcpy(MyString, lpClipMemory)
        RetVal = GlobalUnlock(hClipMemory)
        ' Peel off the null terminating character.
        MyString = Mid(MyString, 1, InStr(1, MyString, Chr$(0), 0) - 1)
    Else
        MsgBox "Could not lock memory to copy string from."
    End If

OutOfHere:
    RetVal = CloseClipboard()
    fapiGetClipboard = MyString
End Function
Function fapiSetClipboard(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

HTH
--
Just my $.001
Dev Ashish
---------------
The Access Web ( http://home.att.net/~dashish )
---------------

:I am creating a app in Access 97 in which I would like to use the clipboard
:object for cutting & pasting text, I inserted the VB objects & procedures
:type library into the references for the database, but whenever I refer to
:the clipboard object, I get the error message "ActiveX component can't
:create object." The help for this error suggests that something is not
:installed correctly, however, the same code works fine in VB. Any
:suggestions?
:
:Rohn
:



Sun, 20 Aug 2000 03:00:00 GMT  
 Using Clipboard object in Access 97

I've written sort of a toolbox with api's and other commonly used
functions.
That's why I use a prefix Tb... everywhere.

I use api calls for handling the clipboard. I found these on a technet CD
and modified them somewhat:

Public Declare Function TbApiOpenClipboard Lib "user32" Alias
"OpenClipboard" (ByVal hwnd As Long) As Long
Public Declare Function TbApiCloseClipboard Lib "user32" Alias
"CloseClipboard" () As Long
Public Declare Function TbApiEmptyClipboard Lib "user32" Alias
"EmptyClipboard" () As Long
Public Declare Function TbApiSetClipboardData Lib "user32" Alias
"SetClipboardData" (ByVal wFormat As Long, _

ByVal hMem As Long) As Long

Public Declare Function TbApiGlobalUnlock Lib "kernel32" Alias
"GlobalUnlock" (ByVal hMem As Long) As Long
Public Declare Function TbApiGlobalLock Lib "kernel32" Alias "GlobalLock"
(ByVal hMem As Long) As Long
Public Declare Function TbApiGlobalAlloc Lib "kernel32" Alias "GlobalAlloc"
(ByVal wFlags As Long, _
                                                                    ByVal
dwBytes As Long) As Long
Public Declare Function TbApiLstrcpy Lib "kernel32" Alias "lstrcpy" (ByVal
lpString1 As Any, _
                                                                    ByVal
lpString2 As Any) As Long
Public Declare Function TbApiGetClipboardData Lib "user32" Alias
"GetClipboardData" (ByVal wFormat As Long) As Long
Public Declare Function TbAliGlobalSize Lib "kernel32" Alias "GlobalSize"
(ByVal hMem As Long) As Long

Public Const TbGHND = &H42
Public Const TbCF_TEXT = 1
Public Const TbMAXSIZE = 4096

Public Function TbClipBoardGetData() As String
On Error GoTo Err_TbClipBoardGetData

Dim hClipMemory As Long
Dim lpClipMemory As Long
Dim strString As String
Dim RetVal As Long

If TbApiOpenClipboard(0&) = 0 Then
   Exit Function
End If

' Obtain the handle to the global memory
' block that is referencing the text.
hClipMemory = TbApiGetClipboardData(TbCF_TEXT)
If IsNull(hClipMemory) Then
   strString = ""
   GoTo Exit_TbClipBoardGetData
End If

' Lock Clipboard memory so we can reference
' the actual data string.
lpClipMemory = TbApiGlobalLock(hClipMemory)

If Not IsNull(lpClipMemory) Then
   strString = Chr(0) & Space$(TbMAXSIZE - 1)
   RetVal = TbApiLstrcpy(strString, lpClipMemory)
   RetVal = TbApiGlobalUnlock(hClipMemory)

   ' Peel off the null terminating character.
   strString = Mid(strString, 1, InStr(1, strString, Chr$(0), 0) - 1)
Else
   strString = ""
End If

Exit_TbClipBoardGetData:
    RetVal = TbApiCloseClipboard()
    TbClipBoardGetData = strString
    Exit Function

Err_TbClipBoardGetData:
    ' use our own errorhandler instead of: Call TbShowError("Function
TbClipBoardGetData []", Erl, Err.Number, Err.Description)
    Resume Exit_TbClipBoardGetData

End Function

Public Function TbClipBoardSetData(strString As String) As Boolean
On Error GoTo Err_TbClipBoardSetData

Dim hGlobalMemory As Long, lpGlobalMemory As Long
Dim hClipMemory As Long, x As Long

' Allocate moveable global memory.
hGlobalMemory = TbApiGlobalAlloc(TbGHND, Len(strString) + 1)

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

' Copy the string to this global memory.
lpGlobalMemory = TbApiLstrcpy(lpGlobalMemory, strString)

' Unlock the memory.
If TbApiGlobalUnlock(hGlobalMemory) <> 0 Then
   GoTo Exit_TbClipBoardSetData
End If

' Open the Clipboard to copy data to.
If TbApiOpenClipboard(0&) = 0 Then
   Exit Function
End If

' Clear the Clipboard.
x = TbApiEmptyClipboard()

' Copy the data to the Clipboard.
hClipMemory = TbApiSetClipboardData(TbCF_TEXT, hGlobalMemory)
TbClipBoardSetData = True

Exit_TbClipBoardSetData:
    Call TbApiCloseClipboard
    Exit Function

Err_TbClipBoardSetData:
    ' use our own errorhandler instead of: Call TbShowError("Function
TbClipBoardSetData []", Erl, Err.Number, Err.Description)
    Resume Exit_TbClipBoardSetData

End Function



Quote:
> I am creating a app in Access 97 in which I would like to use the
clipboard
> object for cutting & pasting text, I inserted the VB objects & procedures
> type library into the references for the database, but whenever I refer
to
> the clipboard object, I get the error message "ActiveX component can't
> create object." The help for this error suggests that something is not
> installed correctly, however, the same code works fine in VB. Any
> suggestions?

> Rohn





Tue, 29 Aug 2000 03:00:00 GMT  
 Using Clipboard object in Access 97

Because VBA does not support the VB clipboard object.

See Dev Ashish's answer for an API method you can use in VBA.

Quote:

>I am creating a app in Access 97 in which I would like to use the clipboard
>object for cutting & pasting text, I inserted the VB objects & procedures
>type library into the references for the database, but whenever I refer to
>the clipboard object, I get the error message "ActiveX component can't
>create object." The help for this error suggests that something is not
>installed correctly, however, the same code works fine in VB. Any
>suggestions?

>Rohn





Tue, 29 Aug 2000 03:00:00 GMT  
 Using Clipboard object in Access 97



Quote:
> Hi,

> Sorry but since I don't know VB, I won't be able to tell you why the code
> works in one place but not in another.  However, I've used the following
set
> of functions before w/o any problems. See if you can use these instead.
> Public Const GHND = &H42
> Public Const MAXSIZE = 4096
> Public Const CF_TEXT = 1
> Private Const CF_ANSIONLY = &H400&
> Private Const CF_APPLY = &H200&
> Private Const CF_BITMAP = 2
> Private Const CF_DIB = 8
> Private Const CF_DIF = 5
> Private Const CF_DSPBITMAP = &H82
> Private Const CF_DSPENHMETAFILE = &H8E
> Private Const CF_DSPMETAFILEPICT = &H83
> Private Const CF_DSPTEXT = &H81
> Private Const CF_EFFECTS = &H100&
> Private Const CF_ENABLEHOOK = &H8&
> Private Const CF_ENABLETEMPLATE = &H10&
> Private Const CF_ENABLETEMPLATEHANDLE = &H20&
> Private Const CF_ENHMETAFILE = 14
> Private Const CF_FIXEDPITCHONLY = &H4000&
> Private Const CF_FORCEFONTEXIST = &H10000
> Private Const CF_GDIOBJFIRST = &H300
> Private Const CF_GDIOBJLAST = &H3FF
> Private Const CF_HDROP = 15
> Private Const CF_INITTOLOGFONTSTRUCT = &H40&
> Private Const CF_LIMITSIZE = &H2000&
> Private Const CF_LOCALE = 16
> Private Const CF_MAX = 17
> Private Const CF_METAFILEPICT = 3
> Private Const CF_NOFACESEL = &H80000
> Private Const CF_NOSCRIPTSEL = &H800000
> Private Const CF_NOSIMULATIONS = &H1000&
> Private Const CF_NOSIZESEL = &H200000
> Private Const CF_NOSTYLESEL = &H100000
> Private Const CF_NOVECTORFONTS = &H800&
> Private Const CF_NOOEMFONTS = CF_NOVECTORFONTS
> Private Const CF_NOVERTFONTS = &H1000000
> Private Const CF_OEMTEXT = 7
> Private Const CF_OWNERDISPLAY = &H80
> Private Const CF_PALETTE = 9
> Private Const CF_PENDATA = 10
> Private Const CF_PRINTERFONTS = &H2
> Private Const CF_PRIVATEFIRST = &H200
> Private Const CF_PRIVATELAST = &H2FF
> Private Const CF_RIFF = 11
> Private Const CF_SCALABLEONLY = &H20000
> Private Const CF_SCREENFONTS = &H1
> Private Const CF_BOTH = (CF_SCREENFONTS Or CF_PRINTERFONTS)
> Private Const CF_SCRIPTSONLY = CF_ANSIONLY
> Private Const CF_SELECTSCRIPT = &H400000
> Private Const CF_SHOWHELP = &H4&
> Private Const CF_SYLK = 4
> Private Const CF_TIFF = 6
> Private Const CF_TTONLY = &H40000
> Private Const CF_UNICODETEXT = 13
> Private Const CF_USESTYLE = &H80&
> Private Const CF_WAVE = 12
> Private Const CF_WYSIWYG = &H8000

> Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags&, ByVal
_
>     dwBytes As Long) As Long
> Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem 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 GlobalUnlock Lib "kernel32" (ByVal hMem As Long)
_
>     As Long
> Private Declare Function OpenClipboard Lib "user32" (ByVal Hwnd As Long)
_
>     As Long
> Private Declare Function CloseClipboard Lib "user32" () As Long
> Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As
_
>     Long) As Long
> Private Declare Function EmptyClipboard Lib "user32" () As Long
> Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat _
>     As Long, ByVal hMem As Long) As Long

> Function fapiGetClipboard()
>     Dim hClipMemory As Long
>     Dim lpClipMemory As Long
>     Dim MyString As String
>     Dim RetVal As Long

>     If OpenClipboard(0&) = 0 Then
>         MsgBox "Cannot open Clipboard. Another app. may have it open"
>         Exit Function
>     End If

>     ' Obtain the handle to the global memory
>     ' block that is referencing the text.
>     hClipMemory = GetClipboardData(CF_TEXT)
>     If IsNull(hClipMemory) Then
>         MsgBox "Could not allocate memory"
>         GoTo OutOfHere
>     End If

>     ' Lock Clipboard memory so we can reference
>     ' the actual data string.
>     lpClipMemory = GlobalLock(hClipMemory)

>     If Not IsNull(lpClipMemory) Then
>         MyString = Space$(MAXSIZE)
>         RetVal = lstrcpy(MyString, lpClipMemory)
>         RetVal = GlobalUnlock(hClipMemory)
>         ' Peel off the null terminating character.
>         MyString = Mid(MyString, 1, InStr(1, MyString, Chr$(0), 0) - 1)
>     Else
>         MsgBox "Could not lock memory to copy string from."
>     End If

> OutOfHere:
>     RetVal = CloseClipboard()
>     fapiGetClipboard = MyString
> End Function
> Function fapiSetClipboard(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

> HTH
> --
> Just my $.001
> Dev Ashish
> ---------------
> The Access Web ( http://home.att.net/~dashish )
> ---------------


> :I am creating a app in Access 97 in which I would like to use the
clipboard
> :object for cutting & pasting text, I inserted the VB objects &
procedures
> :type library into the references for the database, but whenever I refer
to
> :the clipboard object, I get the error message "ActiveX component can't
> :create object." The help for this error suggests that something is not
> :installed correctly, however, the same code works fine in VB. Any
> :suggestions?
> :
> :Rohn
> :




Sun, 03 Sep 2000 03:00:00 GMT  
 Using Clipboard object in Access 97

Quote:



>> Hi,

I'm sorry but did you have a question re: my post?

Dev
--
Please limit questions to newsgroups only...
Just my $.001
Dev Ashish
---------------
The Access Web ( http://home.att.net/~dashish )
---------------

<<snipmaster>>



Sun, 03 Sep 2000 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Clipboard access with Access 97

2. OCX Control Used In Access 97 Runtime - Object Not Found Error

3. Using Access 97 OLE Object fields

4. Clipboard object questions... using the clipboard with vb4

5. How to put text in Clipboard Access 97

6. WMF picture from clipboard in Access 97?

7. Sending text to Word 97 from Access 97 using OLE automation

8. Access Automation Objects - MS Access 97

9. Using VBA to Convert Access 2000 database to Access 97

10. Using Runtime Access 2000 And Full Ver Access 97 Same CPU Same Time

11. distributing an app written in access 2000 runtime but client still uses access 97

12. Using Access 97 and Access 2000 on same machine

 

 
Powered by phpBB® Forum Software