PC Review


Reply
Thread Tools Rate Thread

Check for Null

 
 
=?Utf-8?B?S2lyayBQLg==?=
Guest
Posts: n/a
 
      25th Jul 2006
I've got this code in the After Update event of a text box:

If IsNull([BusUnit]) Then
MsgBox "You must enter a BU.", vbExclamation
Cancel = True
End If

BusUnit is a text field with Allow Zero Length property set to No. I would
expect if I tab past the text box, the AfterUpdate event would fire and I
would get the MsgBox. Nothing is happening. What's wrong?
 
Reply With Quote
 
 
 
 
Allen Browne
Guest
Posts: n/a
 
      25th Jul 2006
The AfterUpdate event of the control does not fire unless the user actually
updates the control.

In any case, you cannot use the control's event to prevent null. You have no
way to know if the user will ever visit the control.

Instead, use the BeforeUpdate event of the *form*

Or, if you don't want to write code, just open the table in design view, and
set the field's Required property to Yes.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Kirk P." <(E-Mail Removed)> wrote in message
news:5CE9AA70-9346-4937-960E-(E-Mail Removed)...
> I've got this code in the After Update event of a text box:
>
> If IsNull([BusUnit]) Then
> MsgBox "You must enter a BU.", vbExclamation
> Cancel = True
> End If
>
> BusUnit is a text field with Allow Zero Length property set to No. I
> would
> expect if I tab past the text box, the AfterUpdate event would fire and I
> would get the MsgBox. Nothing is happening. What's wrong?



 
Reply With Quote
 
=?Utf-8?B?S2lyayBQLg==?=
Guest
Posts: n/a
 
      25th Jul 2006
I did set the fields required property to Yes, and the Allow Zero Length
property to No. That works, but what I was hoping to do was to catch the
error immediately after the user tried to leave the control instead of
waiting until trying to commit the entire record.

I did try using the Before Update event of the form. That catches the error
and displays the MsgBox, but again, I was hoping to notify the user of the
error earlier in the process. Is that even possible?


"Allen Browne" wrote:

> The AfterUpdate event of the control does not fire unless the user actually
> updates the control.
>
> In any case, you cannot use the control's event to prevent null. You have no
> way to know if the user will ever visit the control.
>
> Instead, use the BeforeUpdate event of the *form*
>
> Or, if you don't want to write code, just open the table in design view, and
> set the field's Required property to Yes.
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia.
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "Kirk P." <(E-Mail Removed)> wrote in message
> news:5CE9AA70-9346-4937-960E-(E-Mail Removed)...
> > I've got this code in the After Update event of a text box:
> >
> > If IsNull([BusUnit]) Then
> > MsgBox "You must enter a BU.", vbExclamation
> > Cancel = True
> > End If
> >
> > BusUnit is a text field with Allow Zero Length property set to No. I
> > would
> > expect if I tab past the text box, the AfterUpdate event would fire and I
> > would get the MsgBox. Nothing is happening. What's wrong?

>
>
>

 
Reply With Quote
 
Allen Browne
Guest
Posts: n/a
 
      25th Jul 2006
You could cancel the Exit event of the control.

It would be a rather frustrating interface though: being stuck in a control
and unable to do anything.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Kirk P." <(E-Mail Removed)> wrote in message
news:A0DDF8D8-4497-483A-B4A3-(E-Mail Removed)...
>I did set the fields required property to Yes, and the Allow Zero Length
> property to No. That works, but what I was hoping to do was to catch the
> error immediately after the user tried to leave the control instead of
> waiting until trying to commit the entire record.
>
> I did try using the Before Update event of the form. That catches the
> error
> and displays the MsgBox, but again, I was hoping to notify the user of the
> error earlier in the process. Is that even possible?
>
>
> "Allen Browne" wrote:
>
>> The AfterUpdate event of the control does not fire unless the user
>> actually
>> updates the control.
>>
>> In any case, you cannot use the control's event to prevent null. You have
>> no
>> way to know if the user will ever visit the control.
>>
>> Instead, use the BeforeUpdate event of the *form*
>>
>> Or, if you don't want to write code, just open the table in design view,
>> and
>> set the field's Required property to Yes.
>>
>> "Kirk P." <(E-Mail Removed)> wrote in message
>> news:5CE9AA70-9346-4937-960E-(E-Mail Removed)...
>> > I've got this code in the After Update event of a text box:
>> >
>> > If IsNull([BusUnit]) Then
>> > MsgBox "You must enter a BU.", vbExclamation
>> > Cancel = True
>> > End If
>> >
>> > BusUnit is a text field with Allow Zero Length property set to No. I
>> > would
>> > expect if I tab past the text box, the AfterUpdate event would fire and
>> > I
>> > would get the MsgBox. Nothing is happening. What's wrong?



 
Reply With Quote
 
e.mel
Guest
Posts: n/a
 
      25th Jul 2006
or you could just open the msgbox in the Exit event without cancelling
the event. that would tell them to enter a BU, but not force them to
.. . . until they try to save the record.



Allen Browne wrote:
> You could cancel the Exit event of the control.
>
> It would be a rather frustrating interface though: being stuck in a control
> and unable to do anything.
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia.
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "Kirk P." <(E-Mail Removed)> wrote in message
> news:A0DDF8D8-4497-483A-B4A3-(E-Mail Removed)...
> >I did set the fields required property to Yes, and the Allow Zero Length
> > property to No. That works, but what I was hoping to do was to catch the
> > error immediately after the user tried to leave the control instead of
> > waiting until trying to commit the entire record.
> >
> > I did try using the Before Update event of the form. That catches the
> > error
> > and displays the MsgBox, but again, I was hoping to notify the user of the
> > error earlier in the process. Is that even possible?
> >
> >
> > "Allen Browne" wrote:
> >
> >> The AfterUpdate event of the control does not fire unless the user
> >> actually
> >> updates the control.
> >>
> >> In any case, you cannot use the control's event to prevent null. You have
> >> no
> >> way to know if the user will ever visit the control.
> >>
> >> Instead, use the BeforeUpdate event of the *form*
> >>
> >> Or, if you don't want to write code, just open the table in design view,
> >> and
> >> set the field's Required property to Yes.
> >>
> >> "Kirk P." <(E-Mail Removed)> wrote in message
> >> news:5CE9AA70-9346-4937-960E-(E-Mail Removed)...
> >> > I've got this code in the After Update event of a text box:
> >> >
> >> > If IsNull([BusUnit]) Then
> >> > MsgBox "You must enter a BU.", vbExclamation
> >> > Cancel = True
> >> > End If
> >> >
> >> > BusUnit is a text field with Allow Zero Length property set to No. I
> >> > would
> >> > expect if I tab past the text box, the AfterUpdate event would fire and
> >> > I
> >> > would get the MsgBox. Nothing is happening. What's wrong?


 
Reply With Quote
 
=?Utf-8?B?S2lyayBQLg==?=
Guest
Posts: n/a
 
      25th Jul 2006
That is a good solution. Thanks!

"e.mel" wrote:

> or you could just open the msgbox in the Exit event without cancelling
> the event. that would tell them to enter a BU, but not force them to
> .. . . until they try to save the record.
>
>
>
> Allen Browne wrote:
> > You could cancel the Exit event of the control.
> >
> > It would be a rather frustrating interface though: being stuck in a control
> > and unable to do anything.
> >
> > --
> > Allen Browne - Microsoft MVP. Perth, Western Australia.
> > Tips for Access users - http://allenbrowne.com/tips.html
> > Reply to group, rather than allenbrowne at mvps dot org.
> >
> > "Kirk P." <(E-Mail Removed)> wrote in message
> > news:A0DDF8D8-4497-483A-B4A3-(E-Mail Removed)...
> > >I did set the fields required property to Yes, and the Allow Zero Length
> > > property to No. That works, but what I was hoping to do was to catch the
> > > error immediately after the user tried to leave the control instead of
> > > waiting until trying to commit the entire record.
> > >
> > > I did try using the Before Update event of the form. That catches the
> > > error
> > > and displays the MsgBox, but again, I was hoping to notify the user of the
> > > error earlier in the process. Is that even possible?
> > >
> > >
> > > "Allen Browne" wrote:
> > >
> > >> The AfterUpdate event of the control does not fire unless the user
> > >> actually
> > >> updates the control.
> > >>
> > >> In any case, you cannot use the control's event to prevent null. You have
> > >> no
> > >> way to know if the user will ever visit the control.
> > >>
> > >> Instead, use the BeforeUpdate event of the *form*
> > >>
> > >> Or, if you don't want to write code, just open the table in design view,
> > >> and
> > >> set the field's Required property to Yes.
> > >>
> > >> "Kirk P." <(E-Mail Removed)> wrote in message
> > >> news:5CE9AA70-9346-4937-960E-(E-Mail Removed)...
> > >> > I've got this code in the After Update event of a text box:
> > >> >
> > >> > If IsNull([BusUnit]) Then
> > >> > MsgBox "You must enter a BU.", vbExclamation
> > >> > Cancel = True
> > >> > End If
> > >> >
> > >> > BusUnit is a text field with Allow Zero Length property set to No. I
> > >> > would
> > >> > expect if I tab past the text box, the AfterUpdate event would fire and
> > >> > I
> > >> > would get the MsgBox. Nothing is happening. What's wrong?

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
if date field not null or >0 check check box JK Microsoft Access VBA Modules 4 28th Jan 2009 03:44 PM
Check null RP Microsoft C# .NET 4 12th Nov 2007 04:58 PM
Check if it is null shapper Microsoft ASP .NET 1 11th Oct 2006 08:11 PM
How to check for null tshad Microsoft C# .NET 12 6th Oct 2005 01:28 AM
check for null =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= Microsoft ASP .NET 1 14th Sep 2005 03:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:38 AM.