After Update..Or on Lost Focus

P

Peter

Hi again..i use this code on the lost Focus event..i.e i want the message to
appear if the textbox isleft empty..but it couses Syntax error...Why?

If Me.Apples.Value = IsNull Then
MsgBox "You need to enter a value"
EndSub
 
F

fredg

Hi again..i use this code on the lost Focus event..i.e i want the message to
appear if the textbox isleft empty..but it couses Syntax error...Why?

If Me.Apples.Value = IsNull Then
MsgBox "You need to enter a value"
EndSub

Incorrect event and incorrect code.

If you wish to check for missing data, use the form's BeforeUpdate
event.

Nothing is "= IsNull", but it might be
IsNull([Control]) or [Control IsNull.

Try this in the form's BeforeUpdate event:

If IsNull(Me.[Apples]) Then
MsgBox "You need to enter a value."
Cancel = True
End IF

The Cancel = True will return the user to the form for further entry.
 
P

Peter

And can i use this code for the Forms Before update event for many textboxes?
Thanks!

fredg said:
Hi again..i use this code on the lost Focus event..i.e i want the message to
appear if the textbox isleft empty..but it couses Syntax error...Why?

If Me.Apples.Value = IsNull Then
MsgBox "You need to enter a value"
EndSub

Incorrect event and incorrect code.

If you wish to check for missing data, use the form's BeforeUpdate
event.

Nothing is "= IsNull", but it might be
IsNull([Control]) or [Control IsNull.

Try this in the form's BeforeUpdate event:

If IsNull(Me.[Apples]) Then
MsgBox "You need to enter a value."
Cancel = True
End IF

The Cancel = True will return the user to the form for further entry.
 
P

Peter

and i notice that the forms before update event is occupied with other code..

Peter said:
And can i use this code for the Forms Before update event for many textboxes?
Thanks!

fredg said:
Hi again..i use this code on the lost Focus event..i.e i want the message to
appear if the textbox isleft empty..but it couses Syntax error...Why?

If Me.Apples.Value = IsNull Then
MsgBox "You need to enter a value"
EndSub

Incorrect event and incorrect code.

If you wish to check for missing data, use the form's BeforeUpdate
event.

Nothing is "= IsNull", but it might be
IsNull([Control]) or [Control IsNull.

Try this in the form's BeforeUpdate event:

If IsNull(Me.[Apples]) Then
MsgBox "You need to enter a value."
Cancel = True
End IF

The Cancel = True will return the user to the form for further entry.
 
F

fredg

and i notice that the forms before update event is occupied with other code..

Doesn't matter.

Yes.
If IsNull([ControlA]) or isNull(ControlB]) Then
etc...

fredg said:
On Mon, 8 Jun 2009 14:04:01 -0700, Peter wrote:

Hi again..i use this code on the lost Focus event..i.e i want the message to
appear if the textbox isleft empty..but it couses Syntax error...Why?

If Me.Apples.Value = IsNull Then
MsgBox "You need to enter a value"
EndSub

Incorrect event and incorrect code.

If you wish to check for missing data, use the form's BeforeUpdate
event.

Nothing is "= IsNull", but it might be
IsNull([Control]) or [Control IsNull.

Try this in the form's BeforeUpdate event:

If IsNull(Me.[Apples]) Then
MsgBox "You need to enter a value."
Cancel = True
End IF

The Cancel = True will return the user to the form for further entry.
 
L

Larry Linson

IsNull is not a value... it is a Function which returns True of the value is
Null and False if the value is not Null. It would be written

If IsNull(Me.Apples) Then

or

If IsNull(Me.Apples) = True Then

I have not found the GotFocus and LostFocus to be very "reliable" events for
executing code... I'd use the AfterUpdate event of the Control named
"Applies". You may notice I did not use the .Value property as it is the
default property, that is, it is implied if you do not specify a Property.

Larry Linson
Microsoft Office Access MVP
 

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