Cannot Stop Enter Key From Creating Record

G

Guest

I have an application that evaluates the results of nutrition classes given
to needy people of all ages on how to prepare nutritious meals from the food
received from Harvesters. There are three option groups, three text boxes
and a check box for permission to use their name.

In an effort to insist on accurate data, the user is supposed to click on an
"Add Record" button which uses the Click event procedure and VBA to check the
accuracy of entries. I have added the following code to the Form keypress
event to try to prevent the enter key from being functional at all:

Private Sub Form_KeyPress(KeyAscii As Integer)
On Error GoTo Err_Form_KeyPress
If KeyAscii = vbKeyReturn Then
KeyAscii = 0
End If
Exit_Form_KeyPress:
Exit Sub
Err_Form_KeyPress:
MsgBox "Error: " & Err.Description & " (" & Err.Number & ")"
Resume Exit_Form_KeyPress
End Sub

This seems to work as long as the tab stop is less than the last piece of
data. However, once all entries have been completed, pressing the enter key
creates the record but does not necessarily process the edits in the Add
Record button Click event.

Why does the code seem to work part of the time? I think it is because the
tab function progressively moves execution from one tab stop to next each
time the enter key is pressed as it does in Windows. When it arrives at the
"Add Record" button, it executes the code beneith and progresses to the next
tab stop. This does not seem to stop it from occasionally creating an
inaccurate or blank record. Any ideas would be appreciated on how to stop
the enter key from functioning at all on this form.

EarlCPhillips
Ex-Mainframer Learning Access To Help Feed
the Hungry Through Harvesters Food Bank
 
G

Guest

Is your form's Cycle property set to 'All Records'?
Try changing it to 'Current Record' - that will stop the user from being
able to tab out of the current record.

Steve
 
G

Guest

SteveM; Your suggestion seems to work. You have helped us feed the hungry
and teach them how to prepare nutritious and healthy meals. We can keep
track of our effectiveness. Thanks for your input as it taught me another of
Access's secrets.

EarlCPhillips
Ex-Mainframer Learning Access To Help Feed
the Hungry Through Harvesters Food Bank
 
G

Guest

Another detail is to set all non-data controls to Tab Stop=no and Tab Index
to progressively higher numbers. If not, it seems to interfere with stopping
the Enter key from working normally and creating a record when not intended.

EarlCPhillips
Ex-Mainframer Learning Access To Help Feed
the Hungry Through Harvesters Food Bank
 
A

Albert D. Kallal

EarlCPhillips said:
Another detail is to set all non-data controls to Tab Stop=no and Tab
Index
to progressively higher numbers. If not, it seems to interfere with
stopping
the Enter key from working normally and creating a record when not
intended.

Keep in mind that you can also set the "enter" key as default key to fire a
button, and the "cancel" key (esc key) to cancel on a form.

If you look at the properties sheet for a command button, you see in the
other tab, a setting for

default

If you set default = yes, then when the person hits the enter key, that
button is fired. Thus, you should as a rule teach users to use the tab key
to move through the fields..and then you an make enter key hit you
close/save button.

Quite amazing that ms-access had this feature about 15 years before the web,
but if you look today, you see a lot of web based forms work with tab to
move tot he next field..and hitting enter = save/close.

in the "other" tab, right below "default" is a cancel setting, and if you
set that to "yes", then hitting esc key will fire the button...

So, try to use tab to move to the next...and save the enter key for when
done...you can thus have a new record appear during data entry without users
having to leave the keyboard. I sure with "old" mainframe experience, you
make that effort to allow users to not have to use the keyboard, or even use
the mouse to click on some save button...just have them use the enter
key..and then they get a new record.....
 
M

MILLER2000

WHO EVER HEARD OF A WOMAN LOSING WEIGHT--AND ENJOYING 3 DELICIOUS MEALS AT
THE SAME TIME? I don't know about eating out, but if you are into cook book,
check out my e-mail address. http://www.jshealthyenterprises.com. The cook
book that will help you out is call. THE HEALTHY LIFE COOK BOOK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top