Message Box error

T

Tony Williams

Can someone tell me what's wrong with this code I keep getting error message
saying expected end of statement
Private Sub txtDomfactot_AfterUpdate()
If ([txtDomfacsole] + [txtDomfacpart]) <> [txtDomfactot] Then
MsgBox "Row 1 does not add up" & vbCrLf "It should be
[txtDomfacsole]+[txtDomfacpart]", vbExclamation, "Calculation Error"

End If
End Sub
TIA
Tony
 
B

Brian

Tony Williams said:
Can someone tell me what's wrong with this code I keep getting error message
saying expected end of statement
Private Sub txtDomfactot_AfterUpdate()
If ([txtDomfacsole] + [txtDomfacpart]) <> [txtDomfactot] Then
MsgBox "Row 1 does not add up" & vbCrLf "It should be
[txtDomfacsole]+[txtDomfacpart]", vbExclamation, "Calculation Error"

End If
End Sub
TIA
Tony

From the line break onwards:

& vbCrLf & "It should be " & [txtDomfacsole]+[txtDomfacpart],
vbExclamation, "Calculation Error"
 
T

Tony Williams

Thanks Brian worked perfectly!
Tony
Brian said:
Tony Williams said:
Can someone tell me what's wrong with this code I keep getting error message
saying expected end of statement
Private Sub txtDomfactot_AfterUpdate()
If ([txtDomfacsole] + [txtDomfacpart]) <> [txtDomfactot] Then
MsgBox "Row 1 does not add up" & vbCrLf "It should be
[txtDomfacsole]+[txtDomfacpart]", vbExclamation, "Calculation Error"

End If
End Sub
TIA
Tony

From the line break onwards:

& vbCrLf & "It should be " & [txtDomfacsole]+[txtDomfacpart],
vbExclamation, "Calculation Error"
 
T

Tony Williams

Sorry 1 further question how do I get it to ste focus on the incorrect
field?
Tony
 
F

fredg

Sorry 1 further question how do I get it to ste focus on the incorrect
field?
Tony
Tony Williams said:
Can someone tell me what's wrong with this code I keep getting error message
saying expected end of statement
Private Sub txtDomfactot_AfterUpdate()
If ([txtDomfacsole] + [txtDomfacpart]) <> [txtDomfactot] Then
MsgBox "Row 1 does not add up" & vbCrLf "It should be
[txtDomfacsole]+[txtDomfacpart]", vbExclamation, "Calculation Error"

End If
End Sub
TIA
Tony

Place your corrected code in the BeforeUpdate event, not the
AfterUpdate. Then simply Cancel the event.

Private Sub txtDomfactot_BeforeUpdate(Cancel as Integer)
If ([txtDomfacsole] + [txtDomfacpart]) <> [txtDomfactot] Then
etc.....
Cancel = True
End If
End Sub
 

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