Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2015-02-24
6
Medium Priority
?
152 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
  • 4
  • 2
6 Comments
 
LVL 49

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 49

Accepted Solution

by:
Martin Liss earned 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 49

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 49

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

Industry Leaders: 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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…

885 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