VB Code - IfNull MsgBox

S

Singinbeauty

Alright, I am trying to drive myself mad with this. Please check the
following code and, if you can, tell me why I can't get the focus to stay on
the field 'New Orders'. It just goes to the next field.

What I need to do is if the salesperson leaves a field blank the msgbox will
pop up telling them to enter a value. After hitting retry or cancel the
cursor will stay on the field until they fill it with a number before they
can move on. Thank you for your help!

Private Sub New_Orders_LostFocus()
If IsNull(New_Orders) Then
Dim iAns As Integer
iAns = MsgBox("Please Enter a Value", vbRetryCancel, "REQUIRED")
If iAns = vbCancel Then
Form_LCF![New Orders].SetFocus
Else
Form_LCF![New Orders].SetFocus
End If
End If
End Sub
 
F

fredg

Alright, I am trying to drive myself mad with this. Please check the
following code and, if you can, tell me why I can't get the focus to stay on
the field 'New Orders'. It just goes to the next field.

What I need to do is if the salesperson leaves a field blank the msgbox will
pop up telling them to enter a value. After hitting retry or cancel the
cursor will stay on the field until they fill it with a number before they
can move on. Thank you for your help!

Private Sub New_Orders_LostFocus()
If IsNull(New_Orders) Then
Dim iAns As Integer
iAns = MsgBox("Please Enter a Value", vbRetryCancel, "REQUIRED")
If iAns = vbCancel Then
Form_LCF![New Orders].SetFocus
Else
Form_LCF![New Orders].SetFocus
End If
End If
End Sub

You're using the wrong event, as well as referring to the control
improperly.

Place the following code in the New_Orders BeforeUpdate event:

Private Sub New_Orders_BeforeUpdate(Cancel As Integer)
If IsNull(Me![New Orders]) Then
MsgBox "Please enter a value",vbOKOnly,"Required"
Cancel = True
End If

End Sub
 
S

Singinbeauty

Unfortunately this did not work. The MsgBox didn't even pop up when I hit
tab. Thank you for your help.

fredg said:
Alright, I am trying to drive myself mad with this. Please check the
following code and, if you can, tell me why I can't get the focus to stay on
the field 'New Orders'. It just goes to the next field.

What I need to do is if the salesperson leaves a field blank the msgbox will
pop up telling them to enter a value. After hitting retry or cancel the
cursor will stay on the field until they fill it with a number before they
can move on. Thank you for your help!

Private Sub New_Orders_LostFocus()
If IsNull(New_Orders) Then
Dim iAns As Integer
iAns = MsgBox("Please Enter a Value", vbRetryCancel, "REQUIRED")
If iAns = vbCancel Then
Form_LCF![New Orders].SetFocus
Else
Form_LCF![New Orders].SetFocus
End If
End If
End Sub

You're using the wrong event, as well as referring to the control
improperly.

Place the following code in the New_Orders BeforeUpdate event:

Private Sub New_Orders_BeforeUpdate(Cancel As Integer)
If IsNull(Me![New Orders]) Then
MsgBox "Please enter a value",vbOKOnly,"Required"
Cancel = True
End If

End Sub
 
F

fredg

Unfortunately this did not work. The MsgBox didn't even pop up when I hit
tab. Thank you for your help.

fredg said:
Alright, I am trying to drive myself mad with this. Please check the
following code and, if you can, tell me why I can't get the focus to stay on
the field 'New Orders'. It just goes to the next field.

What I need to do is if the salesperson leaves a field blank the msgbox will
pop up telling them to enter a value. After hitting retry or cancel the
cursor will stay on the field until they fill it with a number before they
can move on. Thank you for your help!

Private Sub New_Orders_LostFocus()
If IsNull(New_Orders) Then
Dim iAns As Integer
iAns = MsgBox("Please Enter a Value", vbRetryCancel, "REQUIRED")
If iAns = vbCancel Then
Form_LCF![New Orders].SetFocus
Else
Form_LCF![New Orders].SetFocus
End If
End If
End Sub

You're using the wrong event, as well as referring to the control
improperly.

Place the following code in the New_Orders BeforeUpdate event:

Private Sub New_Orders_BeforeUpdate(Cancel As Integer)
If IsNull(Me![New Orders]) Then
MsgBox "Please enter a value",vbOKOnly,"Required"
Cancel = True
End If

End Sub

Then the control was not null but empty.
If IsNull([Me!New Orders]) or [New Orders] = "" Then
etc.
 
S

Singinbeauty

I finally figured it out! Thank you for your help! Here is the code I ended
up using...

Private Sub New_Orders_Exit(Cancel As Integer)
If IsNull(New_Orders) Then
Dim iAns As Integer
iAns = MsgBox("Please Enter a Value", vbRetryCancel, "REQUIRED")
Cancel = True
If iAns = vbCancel Then
Me![new orders].SetFocus
Else
Me![new orders].SetFocus
End If
End If
End Sub

Thanks again!

fredg said:
Unfortunately this did not work. The MsgBox didn't even pop up when I hit
tab. Thank you for your help.

fredg said:
On Tue, 11 Apr 2006 09:40:02 -0700, Singinbeauty wrote:

Alright, I am trying to drive myself mad with this. Please check the
following code and, if you can, tell me why I can't get the focus to stay on
the field 'New Orders'. It just goes to the next field.

What I need to do is if the salesperson leaves a field blank the msgbox will
pop up telling them to enter a value. After hitting retry or cancel the
cursor will stay on the field until they fill it with a number before they
can move on. Thank you for your help!

Private Sub New_Orders_LostFocus()
If IsNull(New_Orders) Then
Dim iAns As Integer
iAns = MsgBox("Please Enter a Value", vbRetryCancel, "REQUIRED")
If iAns = vbCancel Then
Form_LCF![New Orders].SetFocus
Else
Form_LCF![New Orders].SetFocus
End If
End If
End Sub

You're using the wrong event, as well as referring to the control
improperly.

Place the following code in the New_Orders BeforeUpdate event:

Private Sub New_Orders_BeforeUpdate(Cancel As Integer)
If IsNull(Me![New Orders]) Then
MsgBox "Please enter a value",vbOKOnly,"Required"
Cancel = True
End If

End Sub

Then the control was not null but empty.
If IsNull([Me!New Orders]) or [New Orders] = "" Then
etc.
 

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