Solved

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

Posted on 2015-02-24
6
101 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 45

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 45

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 45

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 45

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now