Full Version: How do I disable Copy/Paste in an individual form?
UtterAccess Forums > Microsoft® Access > Access Forms
sirchrisofshears
Well, that's pretty much the whole question.
e've had problems with our call centre logging phone numbers incorrectly, so we want them to verify the numbers in a separate box, but we don't want them to simply copy/paste the info they have.
Other forms in the database do still require the copy/paste function so the command mustn't lock the whole database.
Thanks in advance.
bome
The only way I can think of is to empty the clipboard to prevent someone from pasting any text. It can be done by using an API call. Place this code in a code module:
ublic Declare Function EmptyClipboard Lib "user32" () As Long
You can call the function EmptyClipboard in the control's GotFocus event to prevent pasting text.
____________
Bo Melin
sirchrisofshears
How does that work?
created a sub command for gotfocus on the textbox.
Odeclared the function,
then i tried to call the function with:
Private Sub phonenumber2_GotFocus()
Public Declare Function EmptyClipboard Lib "user32" () As Long
EmptyClipboard ()
End Sub
I get an error message saying "Expected ="
bome
The function should not be declared inside the event code. Place it in a module or at the beginning of the form code.
ublic Declare Function EmptyClipboard Lib "user32" () As Long
Private Sub phonenumber2_GotFocus()
EmptyClipboard
End Sub
If that doesn't help use
Private Sub phonenumber2_GotFocus()
Dim lngResult As Long
lngResult = EmptyClipboard
End Sub
to explictly take care of the result returned from the API function.
___________
Bo Melin
sirchrisofshears
It seems to have issues with it being a public function?
bome
Have you tried placing the API function in a module (not in form code module)? Placing it in a module will allow you to use it in any of your forms.
__________
Bo Melin
sirchrisofshears
Yes, that stops the error message but does not disable being able to paste the data from one box to the other... hmmm
bome
Here's a verified and successfully tested solution.
On a module (not form code module) paste this code:
Public Declare Function CloseClipboard Lib "user32" () As Long
Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function EmptyClipboard Lib "user32" () As Long
Change the event code to
Private Sub phonenumber2_GotFocus()
OpenClipboard Me.hwnd
EmptyClipboard
CloseClipboard
End Sub
_________
Bo Melin
sirchrisofshears
You my friend, are a genius laugh.gif
Thank you so much for your help.
*throws Bo a beer*
prebez
Second that sircrisofshears! Jäkla bra ide bome!
Thanks a lot.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.