Re: Checking for null values on form's BeforeUpdate event - How?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



You also made a small error that may interest you. <g>

(You forgot to concatenate the control name to the rest of the message).

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Klatuu" <Klatuu@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:271DD1C6-CDEC-4307-9EBD-7692C89926E2@xxxxxxxxxxxxxxxx
The reason it is setting the focus to the last control that is null is you
are always looping through the entire collection. All you need to do is
bail
out of the For Next loop as soon as you find one that fails. Here is the
fix. Notice I made a small change that may interest you:

If ctl.Tag = "GenericString" Then
If Len(Trim(Nz(ctl, vbNullString))) Then
MsgBox ctl.Name " Requires A Value", vbExclamation + vbOkOnly
Cancel = True
ctl.SetFocus
Exit For
End If
End If

--
Dave Hargis, Microsoft Access MVP


"TryingToLearnVBA" wrote:

Greetings,

I am looking for advice on how to most efficiently write a procedure to
perform the following algorithm on a form's BeforeUpdate event:

1. Cycle through a form's fields (one field at a time)
2. Check for null values or zero length strings (in each field, depending
on
data type?)
3. Display a message box [vbOK] to indicate that the record cannot be
saved
at this time...(if it finds any null or zero length)
4. Cancel the BeforeUpdate event
5. Set focus to the first null or zero length field that it finds

I have researched this topic online and have tried the following
modification of some code I found on this discussion group (see below):

'Dim ctl as Control
'For Each ctl In Me.Section(0).Controls
'If ctl.Tag = "GenericString" Then
' If IsNull(ctl) or Len(ctl) = 0 Then
' MsgBox "GenericStatement", vbOKCancel
' Cancel = True
' ctl.SetFocus
' End If
'End If

The problem with my modified code is that it sets the focus to the last
null
field it finds. Additionally, I am not sure if I am checking the data
thouroughly enough to catch all null values and zero length strings,
because
I am checking fields containing the following three data types: Text,
Number,
and Date?

I appreciate any suggestions. This is my first post, so I apologize if
it
is a bit exhaustive...

END-
--
Thank You.


.



Relevant Pages

  • Re: Checking for null values on forms BeforeUpdate event - How?
    ... Cancel = True ... Dave Hargis, Microsoft Access MVP ... Doug Steele, Microsoft Access MVP ... Check for null values or zero length strings (in each field, ...
    (microsoft.public.access.formscoding)
  • Re: field validation
    ... control until requirements are met before field moves to next control? ... use the BeforeUpdate event of the control and set the Cancel argument to ... Rick Brandt, Microsoft Access MVP ...
    (microsoft.public.access.forms)
  • Re: Quest for the simplest zero voltage switching
    ... a single pot that I could adjust from zero to one hundred percent duty ... cycle input to a zero voltage switching controller chip. ... controller chip would then control the Triac swiching the load. ... As the zero cross switch only switched on zero ...
    (sci.electronics.design)
  • Re: Question on pole-zero cancellation
    ... The numerator includes a zero at DC, the denominator gives a pole at DC, ... and so these cancel, ... Pole-zero cancellations work if the mathematics is exact. ...
    (comp.dsp)
  • Re: Quest for the simplest zero voltage switching
    ... cycle input to a zero voltage switching controller chip. ... controller chip would then control the Triac swiching the load. ... As the zero cross switch only switched on zero ... need to use one comparitor to detect the zero crossing. ...
    (sci.electronics.design)