How to build an If/then /else statements with multiple conditons

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Elvira S. (anonymous_at_discussions.microsoft.com)
Date: 03/01/04


Date: Mon, 1 Mar 2004 15:00:46 -0800

Hi Kathy,

I'd start by looking at the Help menu for If...then
statement. I'm not sure how easy a file it is to find on
the help menu but if you use the office assistant, you can
ask it "If then else statement" and that should take you to
the correct file.

About macros, I'm not sure which version of Access you're
using but macros are more or less outmoded. The main
reason they are still present in later in versions of
Access is for backward compatibility. I don't know anyone
who would recommend using them at this point.

VB is your best bet. It also gives you the option of using
a Select Case Statement, instead of If..Then, if you have
a lot of conditions to deal with.

The If..Then sytax is:

If Condition Then
    code to execute goes here
ElseIf AnotherCondition Then
    code to execute goes here
Else
    code to execute goes here
End If

The Conditions can deal with various things. For instance,
if you want to base your If..Then structure on the value
entered in a control on a form, you might have:

If Me.ctlName Is Null Then....

or it might be a variable you're testing:

If (varName) Not IsNull Then

You can also link your conditions together with operators
like "And" and "Or" and also comparative operators like >=,
Like, Between, etc.

The trouble is that If..Then's with lots of conditions can
be become very confusing to read. That's where Select Case
comes in.

Again, I recommend the Access Help on Select Case.

Also, another useful thing is that you can combine Select
Case and If...Then constructs.

If you need specific help, reply with a description of your
scenario.

Good Luck!
Elvira

>-----Original Message-----
>Hi,
>I am trying to build an If/Then/Else statement with
>several conditions. I took VB several years ago and have
>not used it since the class. Can you recommend a tutorial
>or book etc. that would provide a simple explanation of
>how to build this kind of statement.
>Also I just want to be sure that I should be building a
>module and not a macro for these types of functions?
>
>Thanks so much,
>Kathy
>.
>



Relevant Pages

  • How to build an If/then /else statements with multiple conditons
    ... ElseIf totalvisits = 3 Then ... >using but macros are more or less outmoded. ... > code to execute goes here ... I recommend the Access Help on Select Case. ...
    (microsoft.public.access.modulesdaovba)
  • Re: AutoOpen not Executing When Document Macros Disabled
    ... Normal.dot is already opened and accessible, so the macros therein ... execute regardless of enabling macros within the document? ... another template has code in that template's Document_Open event... ... public routines and two private routines. ...
    (microsoft.public.word.vba.general)
  • Re: Strategies for defining named functions at load or compile time ?
    ... But, one can write the programs that define mathematical formulas as s-expressions, and evaluate the formulas during runtime. ... It cannot be done with macros. ... They barely extend Lisp syntax. ... just like Fortran system can execute Fortran ...
    (comp.lang.lisp)
  • Re: AutoOpen not Executing When Document Macros Disabled
    ... Art H nous racontait que: ... Even when no document are opened, the VBE editor considers that Normal.dot ... so the macros therein execute. ...
    (microsoft.public.word.vba.general)
  • AutoOpen not Executing When Document Macros Disabled
    ... If I answer Enable Macros when opening a document containing macros ... If I answer Disable Macros when opening a document containing macros ... and VBE is closed Normal.dot.NewMacros.AutoOpen and opening document ... AttachedTemplate.ThisDocument.Document_Open do not execute. ...
    (microsoft.public.word.vba.general)