Checking for empty field when leaving a record

andrewf10

Registered User.
Local time
Today, 19:24
Joined
Mar 2, 2003
Messages
114
Hi,

I have yet another problem with my database.

Just before the focus moves from 1 record to another, I need to check whether a certain field has a value in it and if not, to cancel the creation of the record.

What's happening is that users are using the scroll button on the mouse or the navigation buttons which is creating lots of empty records. I'm reluctant to use the 'Required' option on the table because of the problems in trapping this error.

Can someone please give me some ideas?

Many thanks
 
Hi Andrew
I think that the "required" option is the best bet, but here's an idea.

Place somethin like this in the LostFocus section.

Counter = 0

If Me.Field1 = null then
MyField = "Field 1"
Counter = Counter + 1
goto ShowError
end if

If Me.Field2 = null then
MyField = "Field 2"
Counter = Counter + 1
goto ShowError
end if



Exit

ShowError:
msgbox"The field " & MyField & "should contain data. Update now?" vbYesNo

If No then move to next record else put focus on the offending field.

The problem is that users are just going to click on the No button and you will still be sitting with the same problem.
 
Use the BeforeUpdate Event of the form, where you can use Cancel=True if your validation is not met
 
andrewf10,

Check out my old link below. The samples will prevent a user from scrolling to another record unless they do what you want if the current record has been modified but not saved.

A better mouse trap?

HTH
 
Here is a good function posted by Rich that I use all the time for the validation of forms as it is a Module based function that requires minimum code in the forn.
 
Many thanks one and all.

I'm now going to examine each of your ideas and I'll let you know how I get on.
 

Users who are viewing this thread

Back
Top Bottom