[AccessD] Looping through control names

Bob Gajewski rbgajewski at adelphia.net
Fri Jul 16 12:55:07 CDT 2004


Nancy

Then you need a few steps:

1) Create a variable to hold whether ANY mandatory fields are empty.

2) Loop through all controls. If any are empty, set the BackColor for that
field to your desired color, and set the variable  to TRUE.

3) After looping through all fields (outside the For...Next), repaint the
form so the user can see all of the fields missing data. Understand that
they will now have to either TAB through all fields to get to each 'bad'
field <or> click on each one at a time. Unless you want to dynamically
change the tab controls or tags to allow direct jumping from bad field to
next bad field.

Alternatively, you could execute the loop twice. Once to set the BackColor
on all 'bad' fields, and then again to SetFocus.

Regards,

Bob Gajewski


-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Nancy Lytle
Sent: Friday, July 16, 2004 13:48
To: Access Developers discussion and problem solving
Subject: RE: [AccessD] Looping through control names


Thanks for the tips, actually I would like to combine
the two and have the validation at the end of the
form, listing all the fields that must be entered into
and those fields would have the background color
changed, ie Unfilled required fields would be yellow,
corrected field would again become transparent.  That
way one warning, and they can see all of their
"mistakes" at once.

Thanks for the ideas,
Nancy

--- Bob Gajewski <rbgajewski at adelphia.net> wrote:
> Nancy
>
>
> Two schools of thought:
>
> 1) Let the user complete the form, and then validate
> it.
>
> PROS: User allowed to input all data at one time,
> then
> 	validate entire form at end (during [Save] action
> 	or when leaving record?).
>
> CONS: During validation, user receives error for
> EACH
> 	empty field, corrects it, then validation routine
> 	must cycle through all controls again.
>
> 2) Validate each field as completed using
> BeforeUpdate().
>
> PROS: User stopped immediately and required to input
> 	data in empty field before advancing.
>
> CONS: More coding required. Must account for user
> clicking
> 	around form, so may also need validation during
> 	OnBlur event.
>
>
> Regards,
>
> Bob Gajewski
>
> -----Original Message-----
> From: Nancy Lytle [mailto:lytlenj at yahoo.com]
> Sent: Friday, July 16, 2004 1:18 PM
> To: Access Developers discussion and problem Solving
> Subject: [AccessD] Looping through control names
>
>
> I am trying to make the users fill in a whole set of
> fields when they do data entry - almost all fields
> in
> the form must be filled in - this is a new
> requirement.
> I thought the easiest way would be to loop through
> the
> controls that are mandatory (prefixed with mnd) and
> if
> there is one that is null or an empty string to
> require them to go back and fill it in.
> Where I am stuck is on checking the value of the
> data
> in the control.  It doesn't like my code below.
>
> I know I must be missing something simple but I
> can't
> quite get it.
> Any help appreciated.
> Nancy
>
> CODE:
>
> Dim ctl As Control
> For Each ctl In Forms!LCN1
> 'Find the mandatory fields
>      If left(ctl.Name, 3) = "mnd" Then
> 'Check to see if the mandatory field is null
>
> PROBLEM:"object required>
> If ctl.Name.Value Is Null Then
> END PROBLEM (I hope:))
>
> 'Tell them to go back and fill it in
>             MsgBox "You must enter a value for the
> field: " & ctl.Name
> '            ctl.Name.SetFocus
>             Exit Sub
>             Else
> 'If it is not null then end
>             End If
>     Else
> 'if it is not mandatory
>     End If
>  Next
>  'Check next control
>
> --
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> --
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>
>
> --
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>

--
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com





More information about the AccessD mailing list