Solved VBA to check for Null values in certain fields in a form (1 Viewer)

Nagesh

Member
Local time
Today, 06:11
Joined
May 10, 2020
Messages
31
Hi,
Some fields in a form needs to be checked for null entries.
Is there function to determine whether the field is null and 'set focus' to that particular field and also exit code?

I use the below code and repeating the same for each field to check the null value;

Code:
' Check for null entries
If IsNull(Fname) Or Fname = "" Then
    MsgBox "Please fill in your First Name !!"
    Fname.SetFocus
Exit Sub
End If

It would be great if we can use a VB function for this.
 

bob fitz

AWF VIP
Local time
Today, 04:11
Joined
May 23, 2011
Messages
4,719
I would suggest some code in the forms Before Update event (which can be used to stop the form from updating if the validation fails) to loop through all the required controls and test for a value. If no value is found, cancel the update and set the focus to the control with no value and present the user with a message.
 

bob fitz

AWF VIP
Local time
Today, 04:11
Joined
May 23, 2011
Messages
4,719
Another thought. You could just set each fields' "Required" property to "Yes" at the table level.
 

jdraw

Super Moderator
Staff member
Local time
Yesterday, 23:11
Joined
Jan 23, 2006
Messages
15,378
I agree with Bob --use the BeforeUpdate event of the form for your validation checking. That is the last event before the form is saved. You may also involve the Tag property of the controls on the form to be checked.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 11:11
Joined
May 7, 2009
Messages
19,230
there is similar discussion here and i posted an alternative solution.
same thing, add "Tag" to your control. i used "Required" as tag.
see post #10 on this thread for the sample.

 

vhung

Member
Local time
Yesterday, 20:11
Joined
Jul 8, 2020
Messages
235
Hi,
Some fields in a form needs to be checked for null entries.
Is there function to determine whether the field is null and 'set focus' to that particular field and also exit code?

I use the below code and repeating the same for each field to check the null value;

Code:
' Check for null entries
If IsNull(Fname) Or Fname = "" Then
    MsgBox "Please fill in your First Name !!"
    Fname.SetFocus
Exit Sub
End If

It would be great if we can use a VB function for this.
yeah;
>you may use function
>maybe you should try to use:
Select Case "whether the field is null and 'set focus"
then Time Interval for Requery; or maybe to OnLoad Form Event...
 

Nagesh

Member
Local time
Today, 06:11
Joined
May 10, 2020
Messages
31
there is similar discussion here and i posted an alternative solution.
same thing, add "Tag" to your control. i used "Required" as tag.
see post #10 on this thread for the sample.

Thanks arnelgp,
This is exactly what I was looking for !!
 

Users who are viewing this thread

Top Bottom