Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete Record and Confirm with Delete Key

Status
Not open for further replies.

dstew

Programmer
Apr 14, 2003
2
US
Hi - I have a delete control on a form. I want the user to click the delete control and then be required to press the delete key on the keyboard before a record is deleted to prevent accidental deletion. Can someone help me with the code for this?

Thanks so much for your time.
 
This is how I would normally do something like that.

Dim Response As VbMsgBoxResult
Response = MsgBox("Are you sure you want to delete this record?", vbYesNo + vbDefaultButton2)
If Response = vbYes Then
'Goahead and Delete
End If
 
Hi - thanks for the response. That would certainly work, but I need to require the user to press the Delete key on the keyboard, in order to confirm the deletion. I just can't find an example of code that does that.
 
I think you can construct a loop with KeyDown and KeyUp and KeyPress to look for the Delete keypress.

Let me know if something works, I will keep looking and get you a code snippet.

I QUickBaskic, it was very easy, I have lots of programs that do just what you are asking for. I will see if they work in VB.
 
if i am not wrong, you need to know the ascii code for the delete key and then you compare with it in your code.
 
In the Form_Keydown event trap for KeyCode = 46
The Delete key doesn't generate an ASCII number, so Ketpress won't help you

You will of course have to set Form.Keypreview to true


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top