Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713

    Unanswered: Testing part of a field within a Select Case ...

    Hi all.

    I'm making a decision tree to deterine where to write some data for a report. What I need to do is test for a substring within my case statement to know whether to write data in certain columns ... Here is my current Select Case:

    Code:
                Select Case MyRecSet.Fields(5).Value & ""
                    Case ""
                        ' Reg Hours
                        TrgRecSet.Fields(8).Value = MyRecSet.Fields(2).Value
    '                Case Left(MyRecSet.Fields(5).Value, 2) = "OH"
                        ' Reg Hours
    '                    TrgRecSet.Fields(5).Value = MyRecSet.Fields(2).Value
                        ' OT Hours
    '                    TrgRecSet.Fields(6).Value = MyRecSet.Fields(3).Value
                        ' DT Hours
    '                    TrgRecSet.Fields(7).Value = MyRecSet.Fields(4).Value
    
    ' ***** This is the Case in point *****
                    Case "EMP", "FYI", "A7", "STOCK", Left(MyRecSet.Fields(5).Value, 2) = "OH"
                        ' Reg Hours
                        TrgRecSet.Fields(5).Value = MyRecSet.Fields(2).Value
                        ' OT Hours
                        TrgRecSet.Fields(6).Value = MyRecSet.Fields(3).Value
                        ' DT Hours
                        TrgRecSet.Fields(7).Value = MyRecSet.Fields(4).Value
                    Case Else
                        ' Reg Hours
                        TrgRecSet.Fields(2).Value = MyRecSet.Fields(2).Value
                        ' OT Hours
                        TrgRecSet.Fields(3).Value = MyRecSet.Fields(3).Value
                        ' DT Hours
                        TrgRecSet.Fields(4).Value = MyRecSet.Fields(4).Value
                End Select
    Any thoughts on how to test the substring for "OH"?

    Thanks!

  2. #2
    Join Date
    Dec 2003
    Location
    Toronto, Ont. Canada
    Posts
    238

    Re: Testing part of a field within a Select Case ...

    Test for True instead of the field value... and then use the Like operator with a wildcard character after "OH" ... "OH*"
    Code:
                Select Case True
    
                    Case (MyRecSet.Fields(5).Value & "") = ""
                        ' Reg Hours
                        TrgRecSet.Fields(8).Value = MyRecSet.Fields(2).Value
    
                    Case (MyRecSet.Fields(5).Value & "") Like "EMP" Or _
                            (MyRecSet.Fields(5).Value & "") Like "FYI" Or _
                            (MyRecSet.Fields(5).Value & "") Like "A7" Or _
                            (MyRecSet.Fields(5).Value & "") Like "STOCK" Or _
                            (MyRecSet.Fields(5).Value & "") Like "OH*"
                        ' Reg Hours
                        TrgRecSet.Fields(5).Value = MyRecSet.Fields(2).Value
                        ' OT Hours
                        TrgRecSet.Fields(6).Value = MyRecSet.Fields(3).Value
                        ' DT Hours
                        TrgRecSet.Fields(7).Value = MyRecSet.Fields(4).Value
    
                    Case Else
                        ' Reg Hours
                        TrgRecSet.Fields(2).Value = MyRecSet.Fields(2).Value
                        ' OT Hours
                        TrgRecSet.Fields(3).Value = MyRecSet.Fields(3).Value
                        ' DT Hours
                        TrgRecSet.Fields(4).Value = MyRecSet.Fields(4).Value
    
                End Select
    HTH

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •