Checking if all Mandatory fields are completed on a form.

D

D.Bennett

What I need to do is once the client clicks the OK button is to cycle
through 5 text boxes, 2 Frames with option buttons and ensure the all
mandatory fields are filled in on the form. As a start I've been
trying to use the tag property to identify the fields to cycle
through...no problem there. However, what I need to do is check if the
field is null or not. I've tried checking the value and text
propertie, but they're not available using the controls. He's a snip
of the code I've been working with.

Thanks in advance for any help.

Dim ctl As Control
For Each ctl In Me.Controls
Select Case ctl.Tag
Case 1 'controls with a Tag of 1
ctl.SetFocus

If IsNull(ctl.Text) Then <----doesn't work

MsgBox ctl.StatusBarText & " is a Required field."
Else

End If

End Select
Next ctl
 
D

Dirk Goldgar

D.Bennett said:
What I need to do is once the client clicks the OK button is to cycle
through 5 text boxes, 2 Frames with option buttons and ensure the all
mandatory fields are filled in on the form. As a start I've been
trying to use the tag property to identify the fields to cycle
through...no problem there. However, what I need to do is check if the
field is null or not. I've tried checking the value and text
propertie, but they're not available using the controls. He's a snip
of the code I've been working with.

Thanks in advance for any help.

Dim ctl As Control
For Each ctl In Me.Controls
Select Case ctl.Tag
Case 1 'controls with a Tag of 1
ctl.SetFocus

If IsNull(ctl.Text) Then <----doesn't work

MsgBox ctl.StatusBarText & " is a Required field."
Else

End If

End Select
Next ctl

The Text property won't be Null, but what's wrong with the Value
property? I'd have thought that

If IsNull(ctl.Value) Then

would do what you want, and also relieve you of the need to SetFocus to
the control.
 
D

Dave

try using
if nz(ctl.txt,"") = "" then
instead of
If IsNull(ctl.Text) Then

this will return true if the field is empty or null
this will only wok for a text field though

use
nz(ctl.txt,0) = 0 then
for a numeric field


hope this helps
Dave
 
D

D.Bennett

Thanks I'll give it a shot with the text fields...now I just need to
find a way to check the frames/option values. I think I may have found
another way around my problem as well.

I originally tried to check for the value as well - ctl.value, but it
came back with the same problem that the object didn't support it.

Thanks for your input
 
D

Dirk Goldgar

D.Bennett said:
Thanks I'll give it a shot with the text fields...now I just need to
find a way to check the frames/option values. I think I may have found
another way around my problem as well.

I originally tried to check for the value as well - ctl.value, but it
came back with the same problem that the object didn't support it.

That doesn't make sense, unless you were trying that with non-data
controls such as labels, lines, boxes, etc., or maybe controls that are
members of option groups. In that last case you must test the Value of
the option frame, not of the individual buttons or check boxes that are
inside it. I was trusting that you'd only set the Tag property to
include "valued" controls in this test. You really should be using the
Value property, not the Text property, for this test. All data-bindable
controls have a Value property; not all of them have a Text property.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top