ElseIf Usage

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

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
 
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
 
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)

Select Case testexpression
[Case expressionlist-n
[statements-n]] ...
[Case Else
[elsestatements]]
End Select
If condition Then
[statements]
[ElseIf condition-n Then
[elseifstatements] ...
[Else
[elsestatements]]
End If
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

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 807,865 other people just like you!

Top