1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

ElseIf Usage

Discussion in 'Software Development' started by coachdan32, Apr 6, 2004.

Thread Status:
Not open for further replies.
  1. coachdan32

    coachdan32 Thread Starter

    Joined:
    Nov 13, 2003
    Messages:
    1,021
    I have the following code that selects which db the data gets posted to:

    Code:
    If varBusName = "Citi" Then
    Select Case varYrA
    Case "2002"
    varDB = "Training_Delivery_Data.mdb"
    'more Cases for each year
    End Select
    
    Else
    Select Case varYrA
    Case "2002"
    varDB = "Training_Delivery_DataSears.mdb"
    'more Cases for each year
    End Select
    End If
    I am having trouble with users leaving either the year or the business blank - in this case the code is defaulting to the Else choice and posting to the wrong db. I was wondering if I could handle the problem this way:

    Code:
    If varBusName = "Citi" Then
    Select Case varYrA
    Case "2002"
    varDB = "Training_Delivery_Data.mdb"
    'more Cases for each year
    End Select
    
    ElseIF varBusName = "Sears" Then
    Select Case varYrA
    Case "2002"
    varDB = "Training_Delivery_DataSears.mdb"
    'more Cases for each year
    End Select
    
    Else
    'Redirect to an Error Page instructing them to make a choice in the dropdowns
    
    [I][B]How do I get it to check for both values before posting?[/B][/I]
    
    End If
     
  2. MustBNuts

    MustBNuts

    Joined:
    Aug 21, 2003
    Messages:
    2,016
    how about nested Selects?

    Select Case varBusName
    case "citi"
    case "Sears"
    case else
    msgbox "You must choose a business", vbOkOnly
    end Select

    Same situation within the year cases, a case else to provide error message to choose a year.

    MBN
     
  3. AbvAvgUser

    AbvAvgUser

    Joined:
    Oct 3, 2002
    Messages:
    2,281
    Here's an extract from MSDN on the topic. This will give the exact syntax and usage. Hope it helps. What MustBNuts has given is the perfect solution. (y)

     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/217625

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice