SampleSearchOptions.IncludeApprovalAndCompleteData

Syntax Parameters Return Value
- - Boolean

SVB Example

Data Entry Example 11: Searching for sample inconsistencies:

Sub Main

    'Following the "Searching samples for a pattern" example, we discovered an odd pattern of
    'a baker having numerous unacceptable grain-level entries made for her. We suspect that
    'the person who entered and approved the sample data accidentally entered the same entry
    'into 3 separate samples. An easy way to prove this will be to see if any of this baker's
    'grain-level entries are in samples from bakeries that she doesn't even work at.

    Dim oOM As New ObjectManager
    'Reconnect into Enterprise
    oOM.Reconnect Application

    'We know that Gabi works at the Vandalia bakery, so we will limit our search to
    'all the bakeries EXCEPT for Vandalia. If there are any results for her in
    'other bakery samples, then we know there was a mistake.
    Dim Bakeries() As String
    ReDim Bakeries(oOM.Labels("/Blake's Materials/Bakeries").LabelValueList.Count())
    Dim i As Long
    'Make a list of all bakeries from our "Bakeries" label, excluding Vandalia
    For i = 1 To oOM.Labels("/Blake's Materials/Bakeries").LabelValueList.Count
        If StrComp(oOM.Labels("/Blake's Materials/Bakeries").LabelValueList.Item(i), "Vandalia", vbTextCompare) <> 0 Then
            Bakeries(i) = oOM.Labels("/Blake's Materials/Bakeries").LabelValueList.Item(i)
        End If
    Next

    'Specify our search information
    Dim searchInfo As New SampleSearchOptions
    'Search for only approved and completed samples
    searchInfo.IncludeApprovalAndCompleteData = True
    searchInfo.CompleteStatus = swcSampleCompleted
    searchInfo.ApprovalStatus = swcSampleApproved
    'Here we limit our search to all the bakeries except Vandalia
    searchInfo.AddSampleLabelEx(oOM.Labels("/Blake's Materials/Bakeries"), Bakeries)
    'Only look at samples approved by Blake, we suspect he is the admin making mistakes
    searchInfo.Approver = oOM.Users("Blake")
    'We are looking at samples from the Bread Measurements data entry setup
    searchInfo.Profile = oOM.Profiles("/Blake's Materials/Bread Measurements")
    searchInfo.UseSeparateConnection = True

    'Launch the search
    Dim foundSamples As Samples
    Set foundSamples = oOM.DataEntry.SearchSamples(searchInfo)

    'Connect to the first sample
    Dim currentSample As Sample
    Set currentSample = foundSamples.Next

    'A message for our output report
    Dim rptMsg As String, bakeryMismatch As String
    rptMsg = "Samples for Gabi at bakeries she doesn't even work at:" + vbCrLf + _
        "------------------------------------------------------" + vbCrLf

    'Iterate through the search results and record anywhere the baker is named "Gabi".
    'Our search results are excluding Vandalia (the bakery she actually works at), so she shouldn't
    'have any samples in these results.
    While Not(currentSample Is Nothing)

        For i = 1 To currentSample.Data.Pieces.Count
            If currentSample.Data.Pieces(i).FindLabelData(oOM.Labels("/Blake's Materials/Bakers")).Value = "Gabi" Then
                rptMsg = rptMsg & "Sample #" & Trim(Str(currentSample.ID)) & vbTab & _
                "BAKERY: " & currentSample.LabelData(i) & vbCrLf
                'Note: You must call AddSampleLabelEx to include sample labels in the search results.
                'This requirement affects Sample.LabelData().
            End If
        Next

        Set currentSample = foundSamples.Next
    Wend

    'If there is anything in this report, then Blake will have some explaining to do
    Dim rpt As New Report
    rpt.SelectionText = rptMsg
    rpt.Visible = True

    'Disciplinary actions:
    'After discovering Blake's major data entry errors, we also discover that he
    'is in the "Statistician" group; however, he is not a statistician. So here we
    'will remove his membership from this group.
    Dim Blake As User
    Set Blake = oOM.Users("Blake")
    Blake.AutoSave = False
    Blake.MemberOf.Remove("Statistician")
    'Also, remove him from the admin group and move him into the engineers instead.
    Blake.MemberOf.Remove("Administrators")
    Blake.MemberOf.Add(oOM.Groups("Engineer"))
    Dim demotionInfo As New UserUpdateInfo
    demotionInfo.AuditLogReason = "Move him out of statistician and admin groups and into engineers."
    Blake.SaveEx(demotionInfo)

    'We could also terminate him from the company. Uncomment this code
    'to remove him from the system:

    'Dim terminationInfo As New RemoveInfo
    'terminationInfo.AuditLogReason = "Sloppy data entry. He also approved his own samples, which had glaring issues." & vbCrLf & _
    '    "Finally, he recommended terminating a baker--the very one whose data entry he messed up."
    'oOM.Users.RemoveEx("Blake", terminationInfo)

    oOM.Disconnect

End Sub