Select Case Statement Help 
Author Message
 Select Case Statement Help

I am wondering if a Select Case statement would be
applicable here.

 If strInput2 = "OPS" Then
        DoCmd.OpenQuery "qry_OPSUpdate"
    ElseIf strInput2 = "Extruded Foam" Then
        DoCmd.OpenQuery "qry_ExtrudedFoamUpdate"
    ElseIf strInput2 = "Cold Cup" Then
        DoCmd.OpenQuery "qry_ColdCupUpdate"
    ElseIf strInput2 = "Conex Deli" Then
        DoCmd.OpenQuery "qry_ConexUpdate"
    ElseIf strInput2 = "Impact Dinnerware" Then
        DoCmd.OpenQuery "qry_ImpactDinnerwareUpdate"
    ElseIf strInput2 = "Thermoform" Then
        DoCmd.OpenQuery "qry_ThermoFormUpdate"
    ElseIf strInput2 = "HIPS" Then
        DoCmd.OpenQuery "qry_HIPSUpdate"
    ElseIf strInput2 <> "OPS" Or strInput2 <> "Extruded
Foam" Or strInput2 <> "Cold Cup" Or strInput2 <> "Conex
Deli" Or strInput2 <> "Impact Dinnerware" Or strInput2
<> "Thermoform" Then
        If MsgBox(strMsg5, vbRetryCancel, "Error!") =
vbRetry Then
            DoCmd.RunCode "TableUpdate"
        Else: Exit Sub
        End If
    End If

I am a beginner in Access VB and need some basic help
writing this code. If someone could help me out, I would
really appreciate it.



Fri, 19 Nov 2004 20:51:57 GMT  
 Select Case Statement Help

Quote:

>I am wondering if a Select Case statement would be
>applicable here.

> If strInput2 = "OPS" Then
>        DoCmd.OpenQuery "qry_OPSUpdate"
>    ElseIf strInput2 = "Extruded Foam" Then
>        DoCmd.OpenQuery "qry_ExtrudedFoamUpdate"
>    ElseIf strInput2 = "Cold Cup" Then
>        DoCmd.OpenQuery "qry_ColdCupUpdate"
>    ElseIf strInput2 = "Conex Deli" Then
>        DoCmd.OpenQuery "qry_ConexUpdate"
>    ElseIf strInput2 = "Impact Dinnerware" Then
>        DoCmd.OpenQuery "qry_ImpactDinnerwareUpdate"
>    ElseIf strInput2 = "Thermoform" Then
>        DoCmd.OpenQuery "qry_ThermoFormUpdate"
>    ElseIf strInput2 = "HIPS" Then
>        DoCmd.OpenQuery "qry_HIPSUpdate"
>    ElseIf strInput2 <> "OPS" Or strInput2 <> "Extruded
>Foam" Or strInput2 <> "Cold Cup" Or strInput2 <> "Conex
>Deli" Or strInput2 <> "Impact Dinnerware" Or strInput2
><> "Thermoform" Then
>        If MsgBox(strMsg5, vbRetryCancel, "Error!") =
>vbRetry Then
>            DoCmd.RunCode "TableUpdate"
>        Else: Exit Sub
>        End If
>    End If

For most of that sequence, yes it would.

Select Case strInput2
Case "OPS"
        DoCmd.OpenQuery "qry_OPSUpdate"
Case  "Extruded Foam"
                . . .

but your last ElseIf doesn't make sense.  Checking if
strInput2 <> "OPS" Or strInput2 <> "Extruded
will never fail, because strInput2 can never be equal to
both of those values at the same time.  Perhaps you're
trying to check if none of the earlier ElseIf matched?  If
so, then a simple Else would have been the way to code it or
when using Select Case, it would be a Case Else.

--
Marsh
MVP [MS Access]



Fri, 19 Nov 2004 22:00:50 GMT  
 Select Case Statement Help
Eric,

It would certainly be easier to read. By the way, the ElseIf strInput2 <>
line is unnecessary.

Dim strQuery As String
Select Case strInput2
    Case "OPS"
            strQuery = "qry_OPSUpdate"
    Case "Extruded Foam"
            strQuery = "qry_ExtrudedFoamUpdate"
    Case "Cold Cup"
            strQuery = "qry_ColdCupUpdate"
    Case "Conex Deli"
            strQuery = "qry_ConexUpdate"
    Case "Impact Dinnerware"
            strQuery = "qry_ImpactDinnerwareUpdate"
    Case "Thermoform"
            strQuery = "qry_ThermoFormUpdate"
    Case "HIPS"
            strQuery = "qry_HIPSUpdate"
    Case Else
            If MsgBox(strMsg5, vbRetryCancel, "Error!") = vbRetry Then
                DoCmd.RunCode "TableUpdate"
            Else : Exit Sub
            End If
End Select

If Len(strQuery) > 0 Then DoCmd.OpenQuery strQuery

Graham R Seach
Microsoft Access MVP
Sydney, Australia


Quote:
> I am wondering if a Select Case statement would be
> applicable here.

>  If strInput2 = "OPS" Then
>         DoCmd.OpenQuery "qry_OPSUpdate"
>     ElseIf strInput2 = "Extruded Foam" Then
>         DoCmd.OpenQuery "qry_ExtrudedFoamUpdate"
>     ElseIf strInput2 = "Cold Cup" Then
>         DoCmd.OpenQuery "qry_ColdCupUpdate"
>     ElseIf strInput2 = "Conex Deli" Then
>         DoCmd.OpenQuery "qry_ConexUpdate"
>     ElseIf strInput2 = "Impact Dinnerware" Then
>         DoCmd.OpenQuery "qry_ImpactDinnerwareUpdate"
>     ElseIf strInput2 = "Thermoform" Then
>         DoCmd.OpenQuery "qry_ThermoFormUpdate"
>     ElseIf strInput2 = "HIPS" Then
>         DoCmd.OpenQuery "qry_HIPSUpdate"
>     ElseIf strInput2 <> "OPS" Or strInput2 <> "Extruded
> Foam" Or strInput2 <> "Cold Cup" Or strInput2 <> "Conex
> Deli" Or strInput2 <> "Impact Dinnerware" Or strInput2
> <> "Thermoform" Then
>         If MsgBox(strMsg5, vbRetryCancel, "Error!") =
> vbRetry Then
>             DoCmd.RunCode "TableUpdate"
>         Else: Exit Sub
>         End If
>     End If

> I am a beginner in Access VB and need some basic help
> writing this code. If someone could help me out, I would
> really appreciate it.



Fri, 19 Nov 2004 22:18:46 GMT  
 Select Case Statement Help
yes, try something like this

select case strinput2
    case "ops"
        strqry = "qry_OPSUpdate"
    case "Extruded Foam"
        strqry = "Extruded Foam"
etc.....
end select
DoCmd.OpenQuery strqry



Quote:
> I am wondering if a Select Case statement would be
> applicable here.

>  If strInput2 = "OPS" Then
>         DoCmd.OpenQuery "qry_OPSUpdate"
>     ElseIf strInput2 = "Extruded Foam" Then
>         DoCmd.OpenQuery "qry_ExtrudedFoamUpdate"
>     ElseIf strInput2 = "Cold Cup" Then
>         DoCmd.OpenQuery "qry_ColdCupUpdate"
>     ElseIf strInput2 = "Conex Deli" Then
>         DoCmd.OpenQuery "qry_ConexUpdate"
>     ElseIf strInput2 = "Impact Dinnerware" Then
>         DoCmd.OpenQuery "qry_ImpactDinnerwareUpdate"
>     ElseIf strInput2 = "Thermoform" Then
>         DoCmd.OpenQuery "qry_ThermoFormUpdate"
>     ElseIf strInput2 = "HIPS" Then
>         DoCmd.OpenQuery "qry_HIPSUpdate"
>     ElseIf strInput2 <> "OPS" Or strInput2 <> "Extruded
> Foam" Or strInput2 <> "Cold Cup" Or strInput2 <> "Conex
> Deli" Or strInput2 <> "Impact Dinnerware" Or strInput2
> <> "Thermoform" Then
>         If MsgBox(strMsg5, vbRetryCancel, "Error!") =
> vbRetry Then
>             DoCmd.RunCode "TableUpdate"
>         Else: Exit Sub
>         End If
>     End If

> I am a beginner in Access VB and need some basic help
> writing this code. If someone could help me out, I would
> really appreciate it.



Fri, 19 Nov 2004 23:04:37 GMT  
 Select Case Statement Help
Yes it certainly would, as I already informed you about in your initial
"Crituqing code" post on last Friday.

--
Calvin Smith
http://www.CalvinSmithSoftware.com
"Real-world Source Code Solutions"

Mass Emailer - http://www.CalvinSmithSoftware.com/MassEmailer.htm

VB/VBA Tools - http://www.CalvinSmithSoftware.com/AllComboDeals.htm


Quote:
> I am wondering if a Select Case statement would be
> applicable here.

>  If strInput2 = "OPS" Then
>         DoCmd.OpenQuery "qry_OPSUpdate"
>     ElseIf strInput2 = "Extruded Foam" Then
>         DoCmd.OpenQuery "qry_ExtrudedFoamUpdate"
>     ElseIf strInput2 = "Cold Cup" Then
>         DoCmd.OpenQuery "qry_ColdCupUpdate"
>     ElseIf strInput2 = "Conex Deli" Then
>         DoCmd.OpenQuery "qry_ConexUpdate"
>     ElseIf strInput2 = "Impact Dinnerware" Then
>         DoCmd.OpenQuery "qry_ImpactDinnerwareUpdate"
>     ElseIf strInput2 = "Thermoform" Then
>         DoCmd.OpenQuery "qry_ThermoFormUpdate"
>     ElseIf strInput2 = "HIPS" Then
>         DoCmd.OpenQuery "qry_HIPSUpdate"
>     ElseIf strInput2 <> "OPS" Or strInput2 <> "Extruded
> Foam" Or strInput2 <> "Cold Cup" Or strInput2 <> "Conex
> Deli" Or strInput2 <> "Impact Dinnerware" Or strInput2
> <> "Thermoform" Then
>         If MsgBox(strMsg5, vbRetryCancel, "Error!") =
> vbRetry Then
>             DoCmd.RunCode "TableUpdate"
>         Else: Exit Sub
>         End If
>     End If

> I am a beginner in Access VB and need some basic help
> writing this code. If someone could help me out, I would
> really appreciate it.



Sat, 20 Nov 2004 03:20:29 GMT  
 Select Case Statement Help
Calvin,

I did not know how to even write the Select Case code
until now. I am such a beginner that even the Help files
don't offer much. :-)

Thanks to everyone!



Sat, 20 Nov 2004 04:03:00 GMT  
 Select Case Statement Help
Hi Eric,

No problem. Trust me, *we have all been there before*. Just let us know if
you run into trouble. :-)

--
Calvin Smith
http://www.CalvinSmithSoftware.com
"Real-world Source Code Solutions"

Mass Emailer - http://www.CalvinSmithSoftware.com/MassEmailer.htm

VB/VBA Tools - http://www.CalvinSmithSoftware.com/AllComboDeals.htm


Quote:
> Calvin,

> I did not know how to even write the Select Case code
> until now. I am such a beginner that even the Help files
> don't offer much. :-)

> Thanks to everyone!



Sat, 20 Nov 2004 04:36:49 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. VBScript Select Case vs VB Select Case

2. Select Case Statement

3. Criteria for select case statements

4. Embedded or nested Select Case statements

5. Using a wildcard string comparison in a select case statement

6. Select Case statement is driving me mad!

7. Can you nest Select Case statements?

8. If...Then...Else or Select Case Statement

9. Select Case Statement

10. If statement in select case problem

11. Select Case Statement

12. Select Case Statement

 

 
Powered by phpBB® Forum Software