Connecting Tech Pros Worldwide Forums | Help | Site Map

Is this valid syntax (A97 VBA)?

MLH
Guest
 
Posts: n/a
#1: Nov 13 '05
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.

Bob Quintal
Guest
 
Posts: n/a
#2: Nov 13 '05

re: Is this valid syntax (A97 VBA)?


MLH <CRCI@NorthState.net> wrote in
news:jkr7n15rt9atanb7oli27no64bkbofn73i@4ax.com:
[color=blue]
> 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.
>[/color]
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.
MLH
Guest
 
Posts: n/a
#3: Nov 13 '05

re: Is this valid syntax (A97 VBA)?


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[color=blue]
>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[/color]

Arno R
Guest
 
Posts: n/a
#4: Nov 13 '05

re: Is this valid syntax (A97 VBA)?



"MLH" <CRCI@NorthState.net> schreef in bericht news:jp98n19nfn69orgvdms3sdppaesbscikpo@4ax.com...
[color=blue]
> 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?[/color]

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
Bob Quintal
Guest
 
Posts: n/a
#5: Nov 13 '05

re: Is this valid syntax (A97 VBA)?


MLH <CRCI@NorthState.net> wrote in
news:jp98n19nfn69orgvdms3sdppaesbscikpo@4ax.com:
[color=blue]
> 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?[/color]

RTFM.

--
Bob Quintal

PA is y I've altered my email address.
David W. Fenton
Guest
 
Posts: n/a
#6: Nov 13 '05

re: Is this valid syntax (A97 VBA)?


Bob Quintal <rquintal@sympatico.ca> wrote in
news:Xns970AD508A40EBBQuintal@207.35.177.135:
[color=blue]
> IF (NOT isnull(Me!MatlsList)) AND (Me!MatlsCost = 0 OR
> isnull(Me!MatlsCost))[/color]

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
rkc
Guest
 
Posts: n/a
#7: Nov 13 '05

re: Is this valid syntax (A97 VBA)?


Bob Quintal wrote:[color=blue]
> MLH <CRCI@NorthState.net> wrote in
> news:jp98n19nfn69orgvdms3sdppaesbscikpo@4ax.com:
>
>[color=green]
>>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?[/color]
>
>
> RTFM.
>[/color]

Or better yet, RTFM and then WRITE A FREAKING TEST!
MLH
Guest
 
Posts: n/a
#8: Nov 15 '05

re: Is this valid syntax (A97 VBA)?


Not a bad point.
Closed Thread


Similar Microsoft Access / VBA bytes