If boxes don't equal number then msgbox

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
 
F

fredg

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

Thorson

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

Damon Heron

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

Thorson

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
 
M

Marshall Barton

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

Damon Heron

See Marshall's comment - then use brackets [ ]as I suggested instead of
Parentheses( )

Damon
 
T

Thorson

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

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

Similar Threads


Top