View Full Version : Checking for blank fields


Kate
12-04-2001, 05:29 AM
I have some code that checks whether the required fields in a form are completed or not when an "Exit" button is clicked. If a required field is left blank then a messagebox appears and the focus is then set at the field missing information. I got the code from one of the forum topics and it works like a charm.

The problem occurs when a user moves onto a new record but doesn't enter anything in any of the fields and then clicks the Exit button. This sets off a loop that prevents the form from being closed without the user filling in the required fields.

Is there any way I can check if all the fields in the form are empty?

raindrop3
12-04-2001, 06:41 AM
Hello,

I had exactly the same question / problem. I put the following code behind a button:

text1.setfocus
if text1.text = "" then
text2.setfocus
if text2.text = "" then
text3.setfocus
if text3.text = "" then
msgbox "You didn't enter any information!"
text1.setfocus
end if
end if
end if

Maybe there is an easier way to deal with this problem, but this works fine.

Greetings,

Albert

Kate
12-04-2001, 07:28 AM
Sorry, didn't explain myself as well as I thought I did.

I want to be able to close the form if there are no entries at all for the record on screen. Presently, if the record has no entries it starts the loop about completing required fields.

Any ideas?

Pat Hartman
12-04-2001, 06:40 PM
Your code should be in the BeforeUpdate event rather than the Exit event and it should cancel the update if any of your edits detect an error. The BeforeUpdate event is executed whenever Access leaves the current record (or the user specifically requests to save the record using a menu option) but ONLY if the form is DIRTY. Therefore, if NO change has been made, the edits are not performed and the user will not be prevented from moving on.