Public Sub CreateStaticQuery()
    Dim oRecord As CRecord
    Dim oRecords As CRecords
    Set oRecords = New CRecords
    oRecords.Init REApplication.SessionContext

    Dim OStaticQuery As CStaticQ
    Set OStaticQuery = New CStaticQ
    OStaticQuery.Init REApplication.SessionContext

    OStaticQuery.Create SEARCH_CONSTITUENT, "Custom App", Nothing, "Male Constituents", , "Male Constituents"

    For Each oRecord In oRecords
        If oRecord.Fields(RECORDS_fld_GENDER) = "Male" Then
            OStaticQuery.AddRecord oRecord.Fields(RECORDS_fld_ID)
        End If
    Next oRecord

    OStaticQuery.EndCreate Nothing
End Sub

Disclaimer: We provide programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes you are familiar with Microsoft Visual Basic and the tools used to create and debug procedures. Blackbaud Customer Support may help explain the functionality of a particular procedure, but we will not modify, or assist you with modifying, these examples to provide additional functionality.