Hold backspace action (1 Viewer)

dim

Registered User.
Local time
Today, 16:02
Joined
Jul 20, 2012
Messages
54
Hi,

I have a basic form and for entering data, I have to use a keypad (numbers section only) which include a backspace key too.
When a user made a mistake in a specific field, can use the backspace key to correct it but can't move to previous field to make a correction.
I don't know if is possible, but I like to give the possibility to the user to reset the form if will hold the backspace key for more than 5 seconds, so then will start again from the beginning.
So I need a code like,

If SendKeys ("{BACKSPACE}") for >= 5s Then
Docmd.RunMacro "abc"

Thank you for help!
 

Ranman256

Well-known member
Local time
Today, 16:02
Joined
Apr 9, 2015
Messages
4,339
cant you just add a button to clear all fields?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:02
Joined
Oct 29, 2018
Messages
21,454
Hi. Not sure if it’s possible but you could try using both the KeyDown and KeyUp events. On keydown, check the key. If it’s the backspace, start the timer. On keyup, check the timer, if more than 5 sec, then reset the form.
 

dim

Registered User.
Local time
Today, 16:02
Joined
Jul 20, 2012
Messages
54
Thanks for fast replay.
No, I don't have TAB or Escape or Mouse.
 

June7

AWF VIP
Local time
Today, 12:02
Joined
Mar 9, 2014
Messages
5,466
This is an Access db running on a pc? Why is this form so restrictive?
 

dim

Registered User.
Local time
Today, 16:02
Joined
Jul 20, 2012
Messages
54
The idea is to simplify the user action, using only this small keypad (numbers) instate of a big keyboard. Anyway all the data fields are numbers only.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:02
Joined
Feb 19, 2002
Messages
43,231
The problem is that when you type in a control and backspace to "remove" the text, you end up with a ZLS rather than null. Esc is the only way to actually empty the field. So, you will have to take this into consideration when you edit the data.
 

dim

Registered User.
Local time
Today, 16:02
Joined
Jul 20, 2012
Messages
54
To refresh, I have a macro which will close and reopen that form.
I'm not so advanced in vba and my question is more related to start an action after a user press a specific key.
If is not possible the action to start after x seconds using Backspace, what code I have to use to start the action without any delay after the user will press for example the key star "*"?
So I need something like:

Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyStar Then
Docmd.RunMacro "FormRefresh"
End If
End Sub

Thank you
 

June7

AWF VIP
Local time
Today, 12:02
Joined
Mar 9, 2014
Messages
5,466
Form KeyPress event only works if the form has no controls or controls are not visible or are disabled because that's the only way form can get focus.

Would have to use the KeyPress event of controls.

If KeyAscii = 42 Then
 

Users who are viewing this thread

Top Bottom