Logic question driving me crazy!

P

Paolo

Hi,

I'm coding for a message box to pop up should a particular form control
be blank. For reasons too long to explain I'm not using "Is not null"
for the form validation property nor am I using table level validation.
I'm doing all this at Form Unload.

So here's the deal. Me.WorkPack is a yes/no control. If it is true,
then Me.ElementID can't be null, but Me.CostCenter can and so can
Me.ManagerIDElem. If Me.WorkPack is false, neither Me.ElementID nor
Me.CostCenter nor Me.ManagerIDElem can be null.

Question is, how do I construct If then statements to avoid a goto?
That is I could say:

If Me.WorkPack = true and IsNull(Me.ElementID) then goto messagebox
If Me.WorkPack = false and IsNull(Me.ElementID) or
IsNull(Me.CostCenter) or _
IsNull(Me.Elem) then goto MessageBox

MessageBox:
Blahblahblah...

I really want to avoid a goto!

Thanks in advance,
Paolo

I don't check this e-mail. E-mail me here: [email protected],
leaving out NOSPAM.
 
M

Marshall Barton

Paolo said:
I'm coding for a message box to pop up should a particular form control
be blank. For reasons too long to explain I'm not using "Is not null"
for the form validation property nor am I using table level validation.
I'm doing all this at Form Unload.

So here's the deal. Me.WorkPack is a yes/no control. If it is true,
then Me.ElementID can't be null, but Me.CostCenter can and so can
Me.ManagerIDElem. If Me.WorkPack is false, neither Me.ElementID nor
Me.CostCenter nor Me.ManagerIDElem can be null.

Question is, how do I construct If then statements to avoid a goto?
That is I could say:

If Me.WorkPack = true and IsNull(Me.ElementID) then goto messagebox
If Me.WorkPack = false and IsNull(Me.ElementID) or
IsNull(Me.CostCenter) or _
IsNull(Me.Elem) then goto MessageBox

MessageBox:
Blahblahblah...


Won't a single If do it?

If (Me.WorkPack And IsNull(Me.ElementID)) _
OR (Not Me.WorkPack And (IsNull(Me.ElementID) _
Or IsNull(Me.CostCenter) Or IsNull(Me.Elem))) _
Then MessageBox . . .
 
P

Paolo

I think I need to get more sleep. Thanks Marsh.

Marshall said:
Won't a single If do it?

If (Me.WorkPack And IsNull(Me.ElementID)) _
OR (Not Me.WorkPack And (IsNull(Me.ElementID) _
Or IsNull(Me.CostCenter) Or IsNull(Me.Elem))) _
Then MessageBox . . .
 
Top