By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,489 Members | 1,840 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,489 IT Pros & Developers. It's quick & easy.

Is this valid syntax (A97 VBA)?

P: n/a
MLH
380 If Not IsNull(Me!MatlsList) And (Me!MatlsCost = 0 Or
IsNull(Me!MatlsCost)) Then
390 MyMsg = "You entered something in the field entitled
'Materials List' but no charges in the 'Materials' cost field. "
400 MyMsg = MyMsg & "You must enter the amount of the charges in
the field provided or leave the description empty."
410 MsgBox MyMsg, 32, "Amount Required - " & MyApp$ & ", rev. " &
MY_VERSION$
420 Exit Sub
430 End If

Its the IF statement I'm talking about. I've never done an
If This And (This or That)
before and was just wondering if it was permissable.
Nov 13 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
MLH <CR**@NorthState.net> wrote in
news:jk********************************@4ax.com:
380 If Not IsNull(Me!MatlsList) And (Me!MatlsCost = 0 Or
IsNull(Me!MatlsCost)) Then
390 MyMsg = "You entered something in the field entitled
'Materials List' but no charges in the 'Materials' cost field.
" 400 MyMsg = MyMsg & "You must enter the amount of the
charges in the field provided or leave the description empty."
410 MsgBox MyMsg, 32, "Amount Required - " & MyApp$ & ",
rev. " & MY_VERSION$
420 Exit Sub
430 End If

Its the IF statement I'm talking about. I've never done an
If This And (This or That)
before and was just wondering if it was permissable.

Yes, just pay attention to parentheses.

IF (NOT isnull(Me!MatlsList)) AND (Me!MatlsCost = 0 OR
isnull(Me!MatlsCost))

But you can use the NZ function very effectively here to replace
your ORed statements with nz(me!MatlsCost,0) = 0

--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #2

P: n/a
MLH
Thx, Bob Quintal. I appreciate the note on the addn't set
of paren's. I'll test the Nz(Me!MatlsCost,0) = 0 later. Is it
true that if MatlsCost = zero OR is null, that Nz(Me!MatlsCost,0)
will = zero?
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxx
Yes, just pay attention to parentheses.

IF (NOT isnull(Me!MatlsList)) AND (Me!MatlsCost = 0 OR
isnull(Me!MatlsCost))

But you can use the NZ function very effectively here to replace
your ORed statements with nz(me!MatlsCost,0) = 0


Nov 13 '05 #3

P: n/a

"MLH" <CR**@NorthState.net> schreef in bericht news:jp********************************@4ax.com...
I'll test the Nz(Me!MatlsCost,0) = 0 later. Is it
true that if MatlsCost = zero OR is null, that Nz(Me!MatlsCost,0)
will = zero?


I believe we did have a recent and extensive thread on NZ ;-)
I believe it was started by ... hmm..., who was that guy?

Remembers me of a song:
"If you don't know this by now, you will never never never know this ...."

Arno R
Nov 13 '05 #4

P: n/a
MLH <CR**@NorthState.net> wrote in
news:jp********************************@4ax.com:
Thx, Bob Quintal. I appreciate the note on the addn't set
of paren's. I'll test the Nz(Me!MatlsCost,0) = 0 later. Is it
true that if MatlsCost = zero OR is null, that
Nz(Me!MatlsCost,0) will = zero?


RTFM.

--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #5

P: n/a
Bob Quintal <rq******@sympatico.ca> wrote in
news:Xn**********************@207.35.177.135:
IF (NOT isnull(Me!MatlsList)) AND (Me!MatlsCost = 0 OR
isnull(Me!MatlsCost))


I'd not bother with the outer parens, but I'd add a pair of inner
parens:

IF (NOT isnull(Me!MatlsList)) AND ((Me!MatlsCost = 0) OR
isnull(Me!MatlsCost))

The reason is to make clear that (Me!MatlsCost = 0) is a single
expression being evaluated. I always feel it's important to surround
any comparison like that (= or < or > or <> or >= or <=) with parens
to make sure that the right thing is getting evaluated. Keep in mind
that this interpretation:

IF (NOT isnull(Me!MatlsList)) AND (Me!MatlsCost = (0 OR
isnull(Me!MatlsCost)))

would actually be valid, though it's nonsensical, and it forces an
evaluation that is the opposite of the default interpretation.

But, again, I don't believe in depending on default behaviors in
VBA, or in any implicit type coerction (which I think is related).
It may very well be reliable, but it's not good to depend on things
happening the way you expect them to when you can actually *force*
them to make them behave the way you want them to.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #6

P: n/a
rkc
Bob Quintal wrote:
MLH <CR**@NorthState.net> wrote in
news:jp********************************@4ax.com:

Thx, Bob Quintal. I appreciate the note on the addn't set
of paren's. I'll test the Nz(Me!MatlsCost,0) = 0 later. Is it
true that if MatlsCost = zero OR is null, that
Nz(Me!MatlsCost,0) will = zero?

RTFM.


Or better yet, RTFM and then WRITE A FREAKING TEST!
Nov 13 '05 #7

P: n/a
MLH
Not a bad point.
Nov 15 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.