detect data entry

laurat

Registered User.
Local time
Today, 19:40
Joined
Mar 21, 2002
Messages
120
I have a form where data is entered. Once a record is started I would not like the users to be able to close the form until all the required fields have data entered ( I have figured this part out with lots of help). The problem is, a user may open the form and then without entering any data realize they are not ready to start a record so they may want to close the form, however, they cannot because the required fields are empty. Is there any code I could add that would somehow detect if there has been any data entered and if there hasn't been allow them to close the form when they press the 'X'

Thanks.
Laura
 
My date field is automatically set to put in today's date when the form is opened, would that make it dirty once that is put in? I am not quite sure how this 'dirty' thing works.
 
I have gotten an idea from someone but not sure if it will work. Can I set a variable in the open event of the form to true, then set the variable to false once data is entered into any of the fields. Then when the form is closed it checks to see if that variable is true and if so it allows the form to close if not it gives an error message and remains open. This seems as if it would work, however I am not sure where to place all the code. Any suggestions?
 
What was wrong with Pat's suggestion, which requires no code at all?
 
I'm not sure but I think that IsDirty event was new with Access 2000...if you're using 97 or earlier I don't think it is available.
 
.Dirty is a forms thing. However, there are times when .Dirty doesn't help.

The unequivocal way to do this is to test every critical control to see if {control-name}.OldValue = {control-name}.Value

If even one such case exists, the form has been updated. If you have fields for which a default value occurs, you would test to see if the .OldValue = the default for that control.

Use the command-button wizard to generate a command button that allows you to undo a partial data operation. The code it generates will include an UNDO action. You could create TWO buttons. (Bear with me...) one to undo your update before committing it, the other to close your form from the command button. Then look at the two {button-name}_Click routines. Find the code that closes the form. Copy that DoCmd line to immediately follow the DoCmd line that does the UNDO. Then delete the special CLOSE button. 'cause all you really need to add is that second DoCmd following the UNDO.

That way, you get to learn a little bit more about how Access does things behind the scenes. (If you knew more about VBA than this already, sorry. Didn't mean to aim TOO low. But from the sound of your post, you aren't real comfortable with VBA yet.
 

Users who are viewing this thread

Back
Top Bottom