Message Box error

  • Thread starter Thread starter Tony Williams
  • Start date Start date
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
 
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"
 
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"
 
Sorry 1 further question how do I get it to ste focus on the incorrect
field?
Tony
 
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
 
Back
Top