Solved

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

Posted on 2015-02-24
6
138 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 48

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 48

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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 48

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 48

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month7 days, 20 hours left to enroll

617 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