Required fields, "PLEASE ENTER IN THIS FIELD", IT IS REQUIRED. HELP PLEASE (1 Viewer)

jenny23

Registered User.
Local time
Today, 04:11
Joined
Apr 1, 2004
Messages
47
HEllo friends,
I have this question: I have a data entry form.
How do I protect users from skipping fields on the forms? I mean, how do I make sure that a certain field must be filled by user? (required field).
I am new wit ms access, please help.
Example: I have 3 fields on a form, student-id, name, class... they are all required fields. When users fill on the student-id, then move to the name field but don't enter anything, then move to class field. I want a message like this: "please enter on the name field, it is required"

PLEASE HELP.

THANKS
 

Malcy

Registered User.
Local time
Today, 12:11
Joined
Mar 25, 2003
Messages
586
Hi
I use this sort of code
Code:
    If IsNull(Me.txtDoseQc) Or Me.txtDoseQc = "" Then
            MsgBox "You must enter a quick code for the dose", vbOKOnly, "Required data"
            Me.txtDoseQc.SetFocus
        Exit Sub
    End If
You simply rename it to the textbox names on your form. You can also customise the message to what you want, polite or otherwise!
I think you will find it solves the problem.
I tend to put it at the start of the code on the command button when you have finished the form so it checks to see if each required entry is valid but you could put it (I think) in the lost focus event for the textbox.
Hope this helps

Malcy
 
R

Rich

Guest
Use the BeforeUpdate event of the form to Cancel the update if fields have not been entered
 

binghamw

BingleyW
Local time
Today, 04:11
Joined
Apr 22, 2004
Messages
57
Malcy,

Is there a way to do that with two cascading combo boxes?

ie, if, after entering a value in the first combo box, it turns out no values in the second combo box, a msgbox pops up saying, "no values were returned" or something like that?

I tried the code you used above and substituted the name of my combo box where the name of the txt box was, but it didn't work.

binghamw
 

jenny23

Registered User.
Local time
Today, 04:11
Joined
Apr 1, 2004
Messages
47
It doesn't work

I tried both the lost focus and before update event, it shows an error.
My field is not text box, but a combo boxes. Does it make a difference?

Thanks.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:11
Joined
Feb 19, 2002
Messages
43,266
If you need to ensure a value in combo1 to make combo2 active, put the code in the Click event of combo2. Or, in the Current event make combo2 locked if combo1 is null. Then in the AfterUpdate event of combo1, unlock combo2.

If you have required fields, make sure that they are defined as such in the table definition. You can also check for them in the form's BeforeUpdate event if you want to provide your own error message.

Don't EVER use the Lost Focus event for editing. You don't want your editing code to run unless some value has been changed besides, if the user never tabs into a particular control, its Lost Focus event will never be executed. So, if the user uses the mouse to skip over a required field and your code is in the Lost Focus event, the Lost Focus event never fires because the control never obtained the focus in the first place.
 

Malcy

Registered User.
Local time
Today, 12:11
Joined
Mar 25, 2003
Messages
586
Thanks Pat about the Lost Focus bit. I will remember that - it was just a longshot and not one I have used.

Also Jenny, worth making sure that you have called the combo box up properly so that when you enter Me. it should come up with a list of your controls. For a long time I used to call them the same as the field but gradually learned to prefix textboxes with txtWhatever and combo boxes with cboWhatever so it becomes much easier to see where it is going wrong.
Best wishes

Malcy
 

Users who are viewing this thread

Top Bottom