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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stopping the escape key from being pressed twice

Status
Not open for further replies.

NeeNee

Programmer
Apr 2, 2002
97
0
0
CA
I have a form with 3 phone number fields. The user has asked that I preload each field with our local area code so they don't have to enter it.

The problem arises when there is no phone number, they are supposed to press the escape key once to erase the area code and tab to the next field. But if they press the Escape key twice, it deletes all changes to the record on the form. I tried capturing the esc key using the onkeypress event, but then the Escape key does not work at all.

I also tried only putting in the area code when they start entering the phone number of the field, but can't seem to find an event that will work properly.

Thanks.



Denis
Programmer, Canada
 
My current code is in the onEnter event, which means that as soon as they tab in or place the cursor in the field, it add the area code. I was more looking for when they start entering data. I tried onKeyPress for the field, but it kept firing for each key stroke.

Denis

Denis
Programmer, Canada
 
Why not use something like:

Code:
Private Sub Text3_Change()
If Len(Text3.Text) = 1 Then
    Text3 = "000" & Text3.Text
    Text3.SelStart = Len(Text3)
End If
End Sub


-V
 
Thanks, it almost worked, but because I am using an input mask, the length is always 14.

I am at a loss.

Denis
Programmer, Canada
 
I have, what could be, a very dumb question:

Why not just save the record (perhaps triggered after the first esc)? I think saved stuff doesn't get "escape erased" like that. I very quickly tried something like this on a form of mine, it seems to work, and could probably be tweaked to suit your needs.

But, I am seriously green at all this, hence my preface.
 
I just tried adding our area code to the input mask like this: !"(414)"000\-0000;0;#

When you tab to the phone number textbox the input mask shows with our area code. Then, if I don't add any more digits to it and tab past it, the box clears itself. Would that work?
 
it is an unbound form and I don't want to save the record until the user presses the save button (for validation of some fields)

As far as using the input mask with the area code in it. It is a good idea but, it is not possible to change the area code if it is embedded in the input mask, and this is just the default area code.

Thanks for all the suggestions.

Denis
Programmer, Canada
 
What is the input mask you are using? You could try (after modifying to fit the properties of your input mask) something like:

Code:
Private Sub Text3_Change()
If Mid(Text3.Text, 7, 8) = "___-____" Then
    Text3 = "000" & Mid(Text3.Text, 2, 1)
    Text3.SelStart = 7
End If
End Sub


-V
 
Maybe you can do a saveRecord when they hit the esc key. Then the form won't be dirty and the second hit of esc won't do anything. I haven't tried it, though.
 
Assuming you're running Access 2000 or later use Conditional Formatting:

In Design View
Right click on the AreaCode’s textbox
Click on Properties
Click on Data
Set Default Value to whatever the area code is, i.e. = "804"
On the Menus
Goto Format - Conditional Formatting
Under Condition1 change "Field Value Is" to "Expression Is"
In the box to the right enter

IsNull([YourPhoneNumberFieldNameHere])

Now set font color to match background color
Click OK

If the phone number field is empty the area code field will appear empty. No <Esc> key involved!

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Can you set the default values to their input (or store them somewhere) as they enter them? Then have the form repopulate those values should the entire form be cleared under the circumstances you describe?
 
Just my 2 cents worth.
I think it would be easier to have an unbound text box for the area code and concentate the 2 fields (if necessary) after leaving the phone number field.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top