If boxes don't equal number then msgbox

  • Thread starter Thread starter Thorson
  • Start date Start date
T

Thorson

Is there a way to do an IIf statement for text boxes on a form that if the
sum of txtbox 4, 5, 6, and 7 do not equal the number entered in txtbox3 then
a message box pops up saying that the sum is not equal?

Thanks
 
Is there a way to do an IIf statement for text boxes on a form that if the
sum of txtbox 4, 5, 6, and 7 do not equal the number entered in txtbox3 then
a message box pops up saying that the sum is not equal?

Thanks


IIf statement? No.
If Statement? Yes.
And then what do you wish to do after the message is closed?

Code the Form's BeforeUpdate event:
If Me.Nz(Text4) + Me.Nz(Text5) + Me.Nz(Text6) + Me.Nz(Text7) =
Me.[Text3] Then
Else
MsgBox "The sum is not equal."
Cancel = True
End If

The above will cancel the form save and return you to the form for
further entry.
 
That is what I want just the cancel. I tried the code but when I test it out
it s
I get an error saying "Compile Error: Method or data member not found" and
then it highlights .Nz

This is my code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Nz(txtDegenerous) + Me.Nz(txtUnfertilized) + Me.Nz(txtNo2) +
Me.Nz(txtNo1) = Me.[txtNoEmbryos] Then
Else
MsgBox "The sum is not equal."
Cancel = True
End If

End Sub

--
Thorson


fredg said:
Is there a way to do an IIf statement for text boxes on a form that if the
sum of txtbox 4, 5, 6, and 7 do not equal the number entered in txtbox3 then
a message box pops up saying that the sum is not equal?

Thanks


IIf statement? No.
If Statement? Yes.
And then what do you wish to do after the message is closed?

Code the Form's BeforeUpdate event:
If Me.Nz(Text4) + Me.Nz(Text5) + Me.Nz(Text6) + Me.Nz(Text7) =
Me.[Text3] Then
Else
MsgBox "The sum is not equal."
Cancel = True
End If

The above will cancel the form save and return you to the form for
further entry.
 
try it without the NZ test:

If Me.[txtDegenerous] + Me.[txtUnfertilized] + Me.[txtNo2] +
Me.[txtNo1] = Me.[txtNoEmbryos] Then


Damon

Thorson said:
That is what I want just the cancel. I tried the code but when I test it
out
it s
I get an error saying "Compile Error: Method or data member not found" and
then it highlights .Nz

This is my code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Nz(txtDegenerous) + Me.Nz(txtUnfertilized) + Me.Nz(txtNo2) +
Me.Nz(txtNo1) = Me.[txtNoEmbryos] Then
Else
MsgBox "The sum is not equal."
Cancel = True
End If

End Sub

--
Thorson


fredg said:
Is there a way to do an IIf statement for text boxes on a form that if
the
sum of txtbox 4, 5, 6, and 7 do not equal the number entered in txtbox3
then
a message box pops up saying that the sum is not equal?

Thanks


IIf statement? No.
If Statement? Yes.
And then what do you wish to do after the message is closed?

Code the Form's BeforeUpdate event:
If Me.Nz(Text4) + Me.Nz(Text5) + Me.Nz(Text6) + Me.Nz(Text7) =
Me.[Text3] Then
Else
MsgBox "The sum is not equal."
Cancel = True
End If

The above will cancel the form save and return you to the form for
further entry.
 
without the NZ it now just says "Complie Error: Syntax Error" Here is my code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.(txtDegenerous) + Me.(txtUnfertilized) + Me.(txtNo2) + Me.(txtNo1) =
Me.[txtNoEmbryos] Then
Else
MsgBox "The sum is not equal."
Cancel = True
End If
 
Thorson said:
That is what I want just the cancel. I tried the code but when I test it out
it s
I get an error saying "Compile Error: Method or data member not found" and
then it highlights .Nz

This is my code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Nz(txtDegenerous) + Me.Nz(txtUnfertilized) + Me.Nz(txtNo2) +
Me.Nz(txtNo1) = Me.[txtNoEmbryos] Then
Else
MsgBox "The sum is not equal."
Cancel = True
End If

End Sub


The Me. was supposed to be inside the Nz( )

If Nz(Me.txtDegenerous) + Nz(Me.txtUnfertilized) +
Nz(Me.txtNo2) + Nz(Me.txtNo1) = Me.[txtNoEmbryos] Then
Else
....
 
See Marshall's comment - then use brackets [ ]as I suggested instead of
Parentheses( )

Damon
 
Works Perfectly! Thanks!
--
Thorson


Marshall Barton said:
Thorson said:
That is what I want just the cancel. I tried the code but when I test it out
it s
I get an error saying "Compile Error: Method or data member not found" and
then it highlights .Nz

This is my code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Nz(txtDegenerous) + Me.Nz(txtUnfertilized) + Me.Nz(txtNo2) +
Me.Nz(txtNo1) = Me.[txtNoEmbryos] Then
Else
MsgBox "The sum is not equal."
Cancel = True
End If

End Sub


The Me. was supposed to be inside the Nz( )

If Nz(Me.txtDegenerous) + Nz(Me.txtUnfertilized) +
Nz(Me.txtNo2) + Nz(Me.txtNo1) = Me.[txtNoEmbryos] Then
Else
....
 
Back
Top