Form data entry of required fields

tkopari

Board Regular
Joined
Apr 30, 2004
Messages
174
I have a form in which all of the fields are required, and that also has a subform. The people who enter data are not at all Access savvy, and tend to start in random fields in the form, causing it to crash since all the fields are required. How do I get the cursor to always go to the first field and not move to the next field until data has been entered in that field, and then the same for the rest of the fields, in order?

Thanks!

Tony
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
First set the tab order of the controls on the form.

Then program each control's Exit event.
 
Upvote 0
Suggestions for making fields required:
http://www.databasedev.co.uk/required_data.html
http://www.databasedev.co.uk/validate_textbox.html

Note that making the field required at the table level is simplest but the error message(s) are not very understandable to non-experts so you'd still probably want to do the validation at the form level.

I don't think you should try to use exit events to control movement (this won't work very well in practice since you won't fire the exit event until the user tries to exit a control and that won't be very smooth if for instance they are using the mouse to move to another field by clicking in another field -- whoops).

Tab stops are good, useful, and in practice great for form entry - but they only work if users are in the habit of using tab to navigate controls (conversely, if someone does like to use tabs and you have not set the tab stops that can be very frustrating so always set the tab stops).
 
Last edited:
Upvote 0
Thanks everyone! The tab order is already set. I'm going to explain the situation more fully:

A person will walk up to the computer to make an entry, and they'll choose a field that looks good to them, rather than always starting at the top. Then, when they've entered the last field, they get a run-time error pop-up, and they can't go back to the previous fields to fill them in, but instead are forced to close the form and start from scratch....except that virtually no one knows how to re-open the form.

So, to avoid that from happening, I was hoping that the cursor could be forced to always be at the first field when a new record opens (which happens automatically when the previous one has been submitted), and not move until that field is filled in, and so on until all of the fields are filled in.

Is there a way to do that?

Tony
 
Last edited:
Upvote 0
It sounds like you have a bigger problem and are trying to provide a work-around. Sorry to say, but I can't think of a good reason why your db should "crash" as you put it, simply because they don't follow a prescribed order in data entry - aside from the design being faulty. There must be an error message before the form (or database - which is it?) closes on the user. What is/are those messages?
 
Upvote 0
Agree - can't think of a reason for a (fatal) error here that would require reopening the form. What is the message in this "pop up"?
 
Last edited:
Upvote 0
I think the problem is that the users haven't populated all of the required fields when they try to move on to the subform. An entry can't exist in the subform until one exists in the form, so we're getting that error message. I'm a biologist, not a programmer, so I'm not sure how I can fix the design. I'm hoping you all can help with that.

The error message dialog box has the heading "Microsoft Visual Basic" and has the message "Run-time error '2110': Microsoft Access can't move the focus to the control sfrmsaleLineItems", and has the following buttons on the bottom; "Continue" (greyed out), "End", "Debug" and "Help". If I click on the Debug button I get a "Microsoft Visual Basic for Applications" screen with the following code highlighted in yellow and a yellow arrow pointing at it: Me.sfrmSaleLineItems.SetFocus. I'm guessing when the last field in the form is filled, that it's supposed to move down to the subform based on this command, but can't because required fields haven't been populated.


Thanks!

Tony
 
Upvote 0
so... that is a programming error...

You shouldn't be trying to move to the subform with a specific code instruction when that instruction cannot be executed.

Make sure the form is filled in before you try to execute that command!

Yes, this is a chicken-egg thing in a way, but in this case we know that the chicken must come before the egg (validate the form before moving to the subform).
 
Upvote 0
It sounds like the field/control on the main form (parent) that links the main form to the sub form doesn't have the required value, thus no subform records can be created. That would cause the error you describe. Often the approach is to open a main form with the parent field filled in and have that "cascade" to the subform. If the design doesn't allow for that, there are ways to prevent or handle your issue. One prevention is to have the subform invisible until that field is completed, although a label might be required to point that out. Another is to know the sequence of events for forms and controls, and (in your case) validate that the necessary controls contain data, and if not, terminate the process before the event occurs that causes the error.

On the handling side, virtually all code procedures should have an error handling routine, or at least, there should be one not too far up in the hierarchy. When a run time error (not a compile error) occurs, Access looks first in the module containing the code for an error handler. If not found, it looks backwards through any chain of procedure executions - kind of like going up river. If none is found, the default handler takes over. That is what you're experiencing.

If you want to post the code, I/we will see what we can come up with for an error handling routine - unless you want to Google it yourself.
 
Upvote 0

Forum statistics

Threads
1,214,785
Messages
6,121,543
Members
449,038
Latest member
Guest1337

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top