UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Prevent Paste Value, Any Version    
 
   
access2009eg
post Apr 3 2020, 04:58 PM
Post#1



Posts: 1,205
Joined: 19-February 08



Hello friends;

How can prevent paste in the textbox

I used keyascii=0 but still
can use
CTRL +V
to paste the value

--------------------
I would like to Thank you for your help
Go to the top of the page
 
missinglinq
post Apr 3 2020, 05:43 PM
Post#2



Posts: 4,705
Joined: 11-November 02



Found this in my code archives...don't know who to credit.

In a Standard Module, place this code:

CODE
Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function EmptyClipboard Lib "user32" () As Long
Public Declare Function CloseClipboard Lib "user32" () As Long


If you put this in a new Module, name it anything except OpenClipboard, EmptyClipboard or CloseClipboard! Naming Modules the same as the Functions they contain confuses the Access Gnomes, no end!

Then, in your Form, use this:

CODE
Private Sub TargetTextbox_GotFocus()
  OpenClipboard Me.hwnd
  EmptyClipboard
  CloseClipboard
End Sub

Replace TargetTextbox with the actual name of your Textbox.

Copy & Paste will remain intact until you enter the TargetTextbox Control.

Linq ;0)>
This post has been edited by missinglinq: Apr 3 2020, 05:44 PM

--------------------
BTW...The Monkey is laughing at me...not at any other poster!

The problem with making anything foolproof...is that fools are so darn ingenious!

All posts/responses based on Access 2003/2007
Go to the top of the page
 
fkegley
post Apr 3 2020, 09:42 PM
Post#3


UtterAccess VIP
Posts: 23,791
Joined: 13-January 05
From: Mississippi


Not to take away from missingling's response, which I think is pretty cool, you could also try using an AutoKeys macro to redefine the Ctrl-V keypress. I can't do it for you, but there is plenty of documentation on how to do it.

--------------------
Frank Kegley, Microsoft Access 2010 MVP
Go to the top of the page
 
arnelgp
post Apr 3 2020, 10:20 PM
Post#4



Posts: 1,529
Joined: 2-April 09
From: somewhere out there...


on your code, you need also to identify if "Ctrl" key is also pressed aside from "V".

--------------------
Never stop learning, because life never stops teaching.
Go to the top of the page
 
tina t
post Apr 4 2020, 12:44 AM
Post#5



Posts: 6,694
Joined: 11-November 10
From: SoCal, USA


very nice, Linq! - pinpoint action that doesn't disable Paste in the whole database. :)

one thing, i wonder if that code will work in 64-bit Access, or would it need to be tweaked? the op doesn't say what s/he has, and i'm also thinking of others who may read this thread as time goes by...

hth
tina

--------------------
"the wheel never stops turning"
Go to the top of the page
 
arnelgp
post Apr 4 2020, 05:24 AM
Post#6



Posts: 1,529
Joined: 2-April 09
From: somewhere out there...


the only problem so far, is when the
user accidentally place the cursor to the textbox
that clear the clipboard, then set focus to
another textbox to paste.

you can also use Keydown event of the textbox.
this will not clear the clipboard
CODE
Private Sub textboxName_KeyDown(KeyCode As Integer, Shift As Integer)
'check for Ctrl and V
If Shift = 2 And KeyCode = 86 Then KeyCode = 0
End Sub

This post has been edited by arnelgp: Apr 4 2020, 05:25 AM

--------------------
Never stop learning, because life never stops teaching.
Go to the top of the page
 
DanielPineault
post Apr 4 2020, 05:36 AM
Post#7


UtterAccess VIP
Posts: 7,389
Joined: 30-June 11



I'd just point out that as a user I would not be very happy that a developer block such important and native functionality. I can understand stopping copying certain data, but pasting I don't get.

--------------------
Daniel Pineault (2010-2020 Microsoft MVP, UA VIP, EE Distinguished Expert 2018)
Professional Help: https://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: https://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 
missinglinq
post Apr 4 2020, 06:03 AM
Post#8



Posts: 4,705
Joined: 11-November 02



Tina: Don't know...have no way to test.

Daniel: Well, there are situations where you want data to be entered via keyboard rather than copy and pasted into it...for instance, when entering an email address, in order to ensure that it has been entered correctly by comparing two attempts (it's less apt to have been entered incorrectly twice) or when setting up a password. In this situation I'm prone to doing a copy/paste of my first attempt instead of actually re-entering it...which defeats the purpose.

Linq ;0)>

--------------------
BTW...The Monkey is laughing at me...not at any other poster!

The problem with making anything foolproof...is that fools are so darn ingenious!

All posts/responses based on Access 2003/2007
Go to the top of the page
 
DanielPineault
post Apr 4 2020, 06:35 AM
Post#9


UtterAccess VIP
Posts: 7,389
Joined: 30-June 11



I know what you're talking about on web forms, and I just copy/paste those. I do not believe in double entry and certainly not in Access, but I guess that's for another discussion altogether. I don't want to derail this question any further.


Here are the 64-bit declarations, should they be required
CODE
Declare PtrSafe Function OpenClipboard Lib "user32" Alias "OpenClipboard" (ByVal hwnd As LongPtr) As Long
Declare PtrSafe Function EmptyClipboard Lib "user32" Alias "EmptyClipboard" () As Long
Declare PtrSafe Function CloseClipboard Lib "user32" Alias "CloseClipboard" () As Long

--------------------
Daniel Pineault (2010-2020 Microsoft MVP, UA VIP, EE Distinguished Expert 2018)
Professional Help: https://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: https://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 
access2009eg
post Apr 4 2020, 06:56 AM
Post#10



Posts: 1,205
Joined: 19-February 08



Thanks for Great Solutions

thumbup.gif


hat_tip.gif

--------------------
I would like to Thank you for your help
Go to the top of the page
 
missinglinq
post Apr 4 2020, 08:05 AM
Post#11



Posts: 4,705
Joined: 11-November 02



I've only ever used it in Access when users are setting up passwords for Forms.

Thanks, Daniel, for posting the 64-bit declarations...I'll add them to my archived file for future reference!

@access2009eg: Glad we could help!

Liq ;0)>

--------------------
BTW...The Monkey is laughing at me...not at any other poster!

The problem with making anything foolproof...is that fools are so darn ingenious!

All posts/responses based on Access 2003/2007
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    16th July 2020 - 12:24 PM