Solved

Can a textbox be made to not allow pasting into. vb6

Posted on 2015-02-24
6
126 Views
Last Modified: 2015-02-24
I have a vb6 textbox for dates and want to restrict pasting into. Can this be done ?
if yes how? other than clearing the clipboard
0
Comment
Question by:isnoend2001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40628718
Yes but why are you using a textbox if the user can't paste into it? Is typing into it OK?
0
 
LVL 47

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40628774
Just in case someone else wants to jump in with the way to do it before you reply...

Private Sub Text1_KeyPress(KeyAscii As Integer)
' Prevent Ctrl+V
If KeyAscii = 22 Then
    KeyAscii = 0
End If
End Sub

Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
' Prevent Paste
If Button = vbRightButton Then
    Beep
    Clipboard.Clear
    Exit Sub
End If
End Sub

Open in new window

0
 

Author Comment

by:isnoend2001
ID: 40628809
The textbox is for dates that are used as the filename and have to be in a certain format eg
FileName = "mm-dd-yyyy" & ".rtf"
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 47

Expert Comment

by:Martin Liss
ID: 40628812
What does that have to do with pasting?

If you are afraid someone might paste in a wrongly formatted value, why not just add data validation?
0
 

Author Closing Comment

by:isnoend2001
ID: 40628820
Thanks that will work
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40629110
You're welcome. Please be aware that my code in the MouseDown event prevents pasting by clearing the clipboard.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question