Check for Null

G

Guest

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?
 
A

Allen Browne

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.
 
G

Guest

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 said:
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.

Reply to group, rather than allenbrowne at mvps dot org.

Kirk P. said:
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?
 
A

Allen Browne

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.

Reply to group, rather than allenbrowne at mvps dot org.

Kirk P. said:
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 said:
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. said:
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?
 
E

e.mel

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 said:
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.

Reply to group, rather than allenbrowne at mvps dot org.

Kirk P. said:
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 said:
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.

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?
 
G

Guest

That is a good solution. Thanks!

e.mel said:
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 said:
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.

Reply to group, rather than allenbrowne at mvps dot org.

Kirk P. said:
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?


:

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.

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?
 

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