msgbox problems

mousemat

Completely Self Taught
Local time
Today, 21:49
Joined
Nov 25, 2002
Messages
233
I have form which is based on table (I know I know!!!)

However, I have created several buttons to do the work manually. I have a save button of which this code is part of

If Me.Dirty = True Then

If IsNull(ContactName) Or ContactName = "" And IsNull(CompanyName) Or CompanyName = "" Then
MsgBox "You must have a Contact Name or Company Name for this record!", vbOKOnly, "Missing Data"

Basically, a User must enter EITHER a Contact Name OR a Company Name OR both. At least one of the fields needs to be populated.

The code currently produces the message if none of the fields are populated. It also produces the message if CompanyName is populated. It doesn't produce the message the when the ContactName is populated.

What am I doing wrong?
 
Thanks spikepl

Looking at it now, but it still makes no sense. Will keep try though
 
The operator precedence explains why your code reacts as it does.

But your conditions are not right - think about it. An AND requires BOTH sides to be TRUE, and that is not what you want.
 
The conditions are, if both fields are null or "" then present the message. Both sides of the AND are TRUE.

If one side was populated and the other side not populated, the AND would not be true
 

Users who are viewing this thread

Back
Top Bottom