Tech Support Guy banner
Status
Not open for further replies.
1 - 3 of 3 Posts

· Registered
Joined
·
1,057 Posts
Discussion Starter · #1 ·
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
 

· Registered
Joined
·
2,018 Posts
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
 

· Registered
Joined
·
2,313 Posts
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. :up:

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
 
1 - 3 of 3 Posts
Status
Not open for further replies.
Top