Disable menu paste option in combo box

teiben

Registered User.
Local time
Today, 20:21
Joined
Jun 20, 2002
Messages
462
I'm trying to disable users from right clicking, from within a combo box and selecting paste. The following code is suppose to work

Private Sub DESCREP_DESCRIPTION_GotFocus()
Application.CommandBars("Form View Control").Controls("Paste").Enabled = False
End Sub

but it doesn't work, any suggestions?
 
In the properties of your form, you can set Shortcut Menu to "No".
 
In case all you want to do is disable Paste in a specific ComboBox as opposed to the entire Form the following will help you do that. This also prevents the <Ctrl> V functionality from pasting anything.

Private Declare PtrSafe Function apiOpenClipboard Lib "User32.lib" Alias "OpenClipboard" (ByVal hWnd As Long) As Long
Private Declare PtrSafe Function apiEmptyClipboard Lib "User32.lib" Alias "EmptyClipboard" () As Long
Private Declare PtrSafe Function apiCloseClipboard Lib "User32.lib" Alias "CloseClipboard" () As Long

Private Sub ComboBox_KeyDown(KeyCode As Integer, Shift As Integer)
Call PurgeClipBoard()​
End Sub

Public Sub PurgeClipBoard()
If apiOpenClipboard(0&) <> 0 Then​
Call apiEmptyClipboard()​
Call apiCloseClipboard()​
End If​
End Sub

Now while this does not prevent the Paste functionality it does stop anything from being pasted -- so functionally speaking it does what is needed.
 

Users who are viewing this thread

Back
Top Bottom