Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use of wildcard in "Case" statement

Status
Not open for further replies.

CCRT

Technical User
Jul 27, 2005
14
0
0
US
The following snipet of code is from the second tier of 3 cascading combo boxes.

Id like to know if there is a way to use a wildcard instead of typing each Case senerio.

Example: Instead of listing each case "No Power", "No Display", "Error 1" for Electrical problems. I would add a prefix ("E-")to the items in their table ( "E-No Power", "E-No Display", "E-Error 1".....)


Then use one line of code like:
'Direct all Cases that start with "E-" to the table "tblElectricalDetail"
***************************************************
Select Case cboProbLevel1.Value
Case "E-*"
cboProbLevel2.RowSource = "tblElectricalDetail"

********************************************************
I was not sucessful getting the above to work.

' Current code snipet

Code:
Private Sub cboProbLevel1_AfterUpdate()
   On Error Resume Next
 
   Select Case cboProbLevel1.Value
      Case "No Power"
        cboProbLevel2.RowSource = "tblElectricalDetail"
      Case "No Display"
        cboProbLevel2.RowSource = "tblElectricalDetail"
      Case "Error 1"
       cboProbLevel2.RowSource = "tblElectricalDetail"
       Case "Latch"
       cboProbLevel2.RowSource = "tblMechanicalDetail"
   End Select

End Sub



Thanks
--Dave

 
Select Case Left(cboProbLevel1.Value, 2)
Case "E-"
cboProbLevel2.RowSource = "tblElectricalDetail"


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Private Sub cboProbLevel1_AfterUpdate()
On Error Resume Next

Select Case cboProbLevel1.Value
Case "Latch"
cboProbLevel2.RowSource = "tblMechanicalDetail"
Case Else
cboProbLevel2.RowSource = "tblElectricalDetail"
End Select

End Sub

or

Private Sub cboProbLevel1_AfterUpdate()
On Error Resume Next

IF cboProbLevel1.Value = "Latch" Then
cboProbLevel2.RowSource = "tblMechanicalDetail"
Else
cboProbLevel2.RowSource = "tblElectricalDetail"
End If

End Sub
 


FYI,

Your original code, as stated, can be simplified...
Code:
   Select Case cboProbLevel1.Value
      Case "No Power","No Display","Error 1","Latch"
        cboProbLevel2.RowSource = "tblElectricalDetail"
   End Select

Skip,
[sub]
[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top