Multiple Expressions in one sub

P

Peter

Hi all..and thanks for all assistance..

I have a questions regarding more then one expression in a sub..i am dooing
something very wrong..

Private Sub Bag_Status_AfterUpdate()
If Me.Shopping_bag= "Closed" And Not IsNull(Me.Shopping_Sum) Then
MsgBox "blab la bla
End If
End Sub

Above function well...I would like to add the following two expressions in
the same sub

If Me.Shopping_Bag = "Closed" And "Green" (Me.Category) Then
MsgBox "bla bla bla!"

If Me.Type = Fruits And IsNull (Me.Kilograms) Then
MrsBox “blab la blaâ€

Kilograms fieled is by default 0

Am I missing a logical operator..And / Or…

I am doing something wrong..

Thanks!
 
J

Jack Leach

Keep an eye on your parentheses... access has a funny way of deciding what
you're looking for if you don't use them to explicitly let it know.
If Me.Shopping_bag= "Closed" And Not IsNull(Me.Shopping_Sum) Then

If (Me.Shopping_bag = "Closed") And (Not IsNull(Me.Shopping_Sum)) Then

If Me.Shopping_Bag = "Closed" And "Green" (Me.Category) Then

If (Me.Shopping_Bag = "Closed") And (Me.Catagory = "Green") Then

If Me.Type = Fruits And IsNull (Me.Kilograms) Then

If (Me.Type = "Fruits") And (IsNull(Me.Kilograms)) Then

(note Type is a reserved word... you'll want to change that)


This also goes for comparing the same control to different expressions.
Instead of:

If Me.Control = "This" Or "That"

you need...

If (Me.Control = "This") Or (Me.Control = "That")



hth




--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
J

Jack Leach

Instead of:
If Me.Control = "This" Or "That"

you need...

If (Me.Control = "This") Or (Me.Control = "That")


I should correct myself. You don't *need* the parens for this comparison,
but I always put them there anyway. Parents are extremely important when you
start nesting logical comparitors though, and using them even in simple
situation makes the code much more readable and far easier to keep straight
in the mind (IMO) The following line would work fine:

If Me.Control = "This" Or Me.Control = "That"


--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
P

Peter

Thank You Jack!

Jack Leach said:
I should correct myself. You don't *need* the parens for this comparison,
but I always put them there anyway. Parents are extremely important when you
start nesting logical comparitors though, and using them even in simple
situation makes the code much more readable and far easier to keep straight
in the mind (IMO) The following line would work fine:

If Me.Control = "This" Or Me.Control = "That"


--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
S

Stuart McCall

Jack Leach said:
I should correct myself.

That's ok I'll do it for you
Parents are extremely important when you start nesting logical comparitors

They're also very handy when you're short of money

<g> (sorry!)

Seriously though, I totally agree and follow the same rules for the same
reasons.
 
J

Jack Leach

Parents are extremely important when you start nesting logical comparitors
They're also very handy when you're short of money

My parents *always* help me with complex logical comparitor expressions.

If I need extra money it's easy:

(100.00) * (100.00) = PROFIT

<g>

--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top