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

How to stop storing incomplete record?

Status
Not open for further replies.

mph1

Technical User
Sep 13, 2001
451
US
Hi,
I have a basic form (Access 2000). If a user does not fill in certain fields and attempts to save and go to a new record, I want a message to appear and give the user the option to either return and complete or cancel what has been entered and go to a blank form.
I have tried putting code in Before Update (form) and code in On Click (button). The following is some of the code I have been using:
If IsNull(fiels1) or IsNull(field2) Then
MsgBox "Message"
DoCmd.GoToRecord , "Form Name", acNewRec
Any assistance will be greatly appreciated.
Thanks,
Maurie
 
Hi Maurie!

Here's what you need to do:

If IsNull(field1) = True or IsNull(field2) = True Then
If MsgBox ("Field1 and Field2 are required. Do you want to complete this Record?", vbYesNo) = vbYes Then
Cancel = -1
Call Field1.Setfocus
Else
Me.Undo
End If
End If

hth Jeff Bridgham
bridgham@purdue.edu
 
Hi Jeff,

I just tried it and seems to work.
Thanks for your help.

Maurie
 
You can also enforce this at the table level. When you are in the table design, under the 'general' tab, there is a property called 'required' that can be set to 'yes' to require data to be entered into the field. Mike Rohde
"I don't have a god complex, god has a me complex!"
 
Hi Mike!

The table level will work, but an Undo button will need to be added to the form to allow the user to not save the record if that is their choice.

Jeff Bridgham
bridgham@purdue.edu
 
Good point, Jeff!!!

Most of our users have enough computer savy to know that they can press 'Escape' to cancel the record, but relying on the intelligence of the users can be dangerous ;-)

We also have some rare cases where the data is edited at the table level, so this is the only way to force them to put data in the field.

Depending on the situation, you could also use 'validation rule' and 'validation text' so you can customize the error message that the user gets (i.e. tell them to press escape to cancel the record or enter the missing data).

Jeff's solution works very well, I just wanted to point out this alternative which may or may not be easier depending on the situation.

Mike Rohde
"I don't have a god complex, god has a me complex!"
 
Hi Mike!

You also make very good points! Most of my users tend to be less computer literate, so I try to keep them away from the tables. But you are correct, if the users have access to direct entry in the tables, some sort of table level validation is important.

Our jobs would be easier if no one would use our databases! :) Unfortunately, we would also be unnecessary!

Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top