Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 168
  • Last Modified:

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

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
isnoend2001
Asked:
isnoend2001
  • 4
  • 2
1 Solution
 
Martin LissRetired ProgrammerCommented:
Yes but why are you using a textbox if the user can't paste into it? Is typing into it OK?
0
 
Martin LissRetired ProgrammerCommented:
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
 
isnoend2001Author Commented:
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
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!

 
Martin LissRetired ProgrammerCommented:
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
 
isnoend2001Author Commented:
Thanks that will work
0
 
Martin LissRetired ProgrammerCommented:
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!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now