Testing for required data entry in form fields.


G

Gina

On my form, there are 2 combo boxes and a few other bound text boxes.
All have been tagged as "Required". I want to test that all the form
fields have been entered before the form is closed.

The user selects a value in combo 1. In the afterupdate event of combo
1, combo 2 is requeried to narrow down the selections available. The
user is then required to make a selection from combo 2.

On the close button I have this code to check that all the fields on
the form have been entered.

If Me.Dirty Then
For Each ctl In Me
If ctl.Tag = "Required" And IsNull(ctl) Then
MsgBox ctl.Name & " must be entered."
ctl.SetFocus
Exit Sub
End If
Next ctl
End If

This code works for all the fields except combo 2. The form will
close with no error message if all fields have been populated but
combo 2 is left blank.


I am stumped as to why this should happen. Can anyone help?
 
Ad

Advertisements

J

John W. Vinson

On my form, there are 2 combo boxes and a few other bound text boxes.
All have been tagged as "Required". I want to test that all the form
fields have been entered before the form is closed.

The user selects a value in combo 1. In the afterupdate event of combo
1, combo 2 is requeried to narrow down the selections available. The
user is then required to make a selection from combo 2.

On the close button I have this code to check that all the fields on
the form have been entered.

If Me.Dirty Then
For Each ctl In Me
If ctl.Tag = "Required" And IsNull(ctl) Then
MsgBox ctl.Name & " must be entered."
ctl.SetFocus
Exit Sub
End If
Next ctl
End If

This code works for all the fields except combo 2. The form will
close with no error message if all fields have been populated but
combo 2 is left blank.


I am stumped as to why this should happen. Can anyone help?

Sounds like the Required tag is not set on combo2. If you put a breakpoint on
the code at the line If ctl.Tag = "Required", you should be able to step
through the code until combo2 is reached, and check its Tag property (and its
value).

If the control could contain a zero length string, it would be a bit safer to
test

.... And Len(ctl & "") = 0

instead of IsNull(ctl).
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 
G

Gina

Sounds like the Required tag is not set on combo2. If you put a breakpoint on
the code at the line If ctl.Tag = "Required", you should be able to step
through the code until combo2 is reached, and check its Tag property (andits
value).

If the control could contain a zero length string, it would be a bit safer to
test

... And Len(ctl & "") = 0

instead of IsNull(ctl).
--

             John W. Vinson [MVP]
 Microsoft's replacements for these newsgroups:
 http://social.msdn.microsoft.com/Forums/en-US/accessdev/
 http://social.answers.microsoft.com/Forums/en-US/addbuz/
 and see alsohttp://www.utteraccess.com- Hide quoted text -

- Show quoted text -

Thanks for your response John. All the fields are correctly tagged.
Changing the code as you suggest to:

If ctl.Tag = "Required" And Len(ctl & "") = 0

produces an error message "Object doesn't support this property or
method".

Still stumped. Interestingly, if I change combo 2 to an unbound
control (which I don't want), the tag property DOES work. Does that
suggest anything?
 
J

John W. Vinson

Thanks for your response John. All the fields are correctly tagged.
Changing the code as you suggest to:

If ctl.Tag = "Required" And Len(ctl & "") = 0

produces an error message "Object doesn't support this property or
method".

Still stumped. Interestingly, if I change combo 2 to an unbound
control (which I don't want), the tag property DOES work. Does that
suggest anything?

Try Len(ctl.Value & "") instead - I guess the control as a variable doesn't
default the same way as the control object itself.

What are the combo box's RowSource and ControlSource? If you step through your
previous code in debug mode, what is the value of ctl when it reaches that
combo?
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 
G

Gina

Try Len(ctl.Value & "") instead - I guess the control as a variable doesn't
default the same way as the control object itself.

What are the combo box's RowSource and ControlSource? If you step throughyour
previous code in debug mode, what is the value of ctl when it reaches that
combo?
--

             John W. Vinson [MVP]
 Microsoft's replacements for these newsgroups:
 http://social.msdn.microsoft.com/Forums/en-US/accessdev/
 http://social.answers.microsoft.com/Forums/en-US/addbuz/
 and see alsohttp://www.utteraccess.com

Nope - makes no difference adding the .value.

Not too familiar with debugging mode. Run to cursor? Place a
breakpoint. Can't get it to step through - keeps saying there is no
"executable statement".

Here's the design of the 2 combos if that helps.

combo1 unbound (cboCourseType)

combo1 row source:
SELECT lkpTrainingType.fldTrainingTypeID,
lkpTrainingType.fldTrainingTypeDescription
FROM lkpTrainingType;



combo 2 (cboCourseTitle) control source:
fldCourseID


combo2 row source:

SELECT tblTrainingCourses.fldCourseID,
tblTrainingCourses.fldCourseDescription, tblTrainingCourses.fldTypeID
FROM tblTrainingCourses
WHERE (((tblTrainingCourses.fldTypeID)=[Forms].
[frmCreateTrainingSession]![cboCourseType]))
ORDER BY tblTrainingCourses.fldCourseDescription;


after update combo1:
Me!cboCourseTitle.Enabled = True
Me!cboCourseTitle.requery
 
J

John W. Vinson

Gina, were you ever able to get this working?

Try Len(ctl.Value & "") instead - I guess the control as a variable doesn't
default the same way as the control object itself.

What are the combo box's RowSource and ControlSource? If you step through your
previous code in debug mode, what is the value of ctl when it reaches that
combo?
--

             John W. Vinson [MVP]
 Microsoft's replacements for these newsgroups:
 http://social.msdn.microsoft.com/Forums/en-US/accessdev/
 http://social.answers.microsoft.com/Forums/en-US/addbuz/
 and see alsohttp://www.utteraccess.com

Nope - makes no difference adding the .value.

Not too familiar with debugging mode. Run to cursor? Place a
breakpoint. Can't get it to step through - keeps saying there is no
"executable statement".

Here's the design of the 2 combos if that helps.

combo1 unbound (cboCourseType)

combo1 row source:
SELECT lkpTrainingType.fldTrainingTypeID,
lkpTrainingType.fldTrainingTypeDescription
FROM lkpTrainingType;



combo 2 (cboCourseTitle) control source:
fldCourseID


combo2 row source:

SELECT tblTrainingCourses.fldCourseID,
tblTrainingCourses.fldCourseDescription, tblTrainingCourses.fldTypeID
FROM tblTrainingCourses
WHERE (((tblTrainingCourses.fldTypeID)=[Forms].
[frmCreateTrainingSession]![cboCourseType]))
ORDER BY tblTrainingCourses.fldCourseDescription;


after update combo1:
Me!cboCourseTitle.Enabled = True
Me!cboCourseTitle.requery
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 
Ad

Advertisements

G

Gina

Gina, were you ever able to get this working?




Nope - makes no difference adding the .value.
Not too familiar with debugging mode.  Run to cursor? Place a
breakpoint. Can't get it to step through - keeps saying there is no
"executable statement".
Here's the design of the 2 combos if that helps.
combo1 unbound (cboCourseType)
combo1 row source:
SELECT lkpTrainingType.fldTrainingTypeID,
lkpTrainingType.fldTrainingTypeDescription
FROM lkpTrainingType;
combo 2 (cboCourseTitle) control source:
fldCourseID
combo2 row source:
SELECT tblTrainingCourses.fldCourseID,
tblTrainingCourses.fldCourseDescription, tblTrainingCourses.fldTypeID
FROM tblTrainingCourses
WHERE (((tblTrainingCourses.fldTypeID)=[Forms].
[frmCreateTrainingSession]![cboCourseType]))
ORDER BY tblTrainingCourses.fldCourseDescription;
after update combo1:
Me!cboCourseTitle.Enabled = True
Me!cboCourseTitle.requery

--

             John W. Vinson [MVP]
 Microsoft's replacements for these newsgroups:
 http://social.msdn.microsoft.com/Forums/en-US/accessdev/
 http://social.answers.microsoft.com/Forums/en-US/addbuz/
 and see alsohttp://www.utteraccess.com- Hide quoted text -

- Show quoted text -

Hi John,

There you are! I thought you had forgotten me:) Today is the first
time I have seen your last post. For some reason, my view of this
group has not been updating.

No, my problem is still there - and my last post above is still the
current position.

Gina.
 

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