Notices


Reply
 
LinkBack Thread Tools Display Modes

Old 05-13-2008, 08:21 PM   #1 (permalink)
Junior Member

Join Date: Sep 2007
Posts: 11
Rep Power: 0 mobius is on a distinguished road

Blackbaud Products
- Raiser's Edge (RE)
- API/VBA

Share your most useful RE VBA Code/Function

One of the things I found most helpful when learning VBA was viewing some of the utility code that someone else had left on our instance of RE. Not only were they great examples, but they really simplified tasks which I find I need to do all the time.

I'm sure we all have a long list of functions we call on a regular basis that we've created, so don't keep them a secret, share them with the community! Maybe someone keen could create a wiki if the thread gets too big...

So my first submission is a simple procedure that loads a query into a listview control.
Caveat-no error trapping in this one!

Code:
Public Sub LoadQueryIntoListView(oListView As ListView, strQueryName As String)

    Dim ColCtr As Long
    Dim RowCtr As Long
    Dim strRowData As String
    Dim strColName As String

    Dim oQueryObject As CQueryObject
    Set oQueryObject = New CQueryObject

    oQueryObject.Init REApplication.SessionContext

    'Load using the Query name
    oQueryObject.LoadByField uf_QUERY_NAME, strQueryName

    'This opens the resultset for access
    oQueryObject.QuerySet.OpenQuerySet
    
    ' Load Array Headers into ListView
    oListView.ColumnHeaders.Clear
    
    ' Add the row number column as column 0
    With oListView.ColumnHeaders.Add
        .Text = "Row"
        .Width = 20
    End With
    
    ' Now load the columns from the query
    For ColCtr = 1 To oQueryObject.QuerySet.FieldCount
        strColName = oQueryObject.QuerySet.FieldName(ColCtr)
        With oListView.ColumnHeaders.Add
            .Text = strColName
          '  .Width = Utils.GetColumnWidth(strColName) * 0.05 'Use your own code here if you like
        End With
    Next
    
    If oQueryObject.QuerySet.NumberOfRecords > 0 Then
        ' Now load the Rows from the query
        For RowCtr = 1 To oQueryObject.QuerySet.NumberOfRecords
            oListView.ListItems.Add , , RowCtr
            For ColCtr = 1 To oQueryObject.QuerySet.FieldCount
                oListView.ListItems(RowCtr).SubItems(ColCtr) = oQueryObject.QuerySet.fieldValue(ColCtr)
            Next ColCtr
            oQueryObject.QuerySet.MoveNext
        Next RowCtr
    End If
    
    ' Tidy Up
    oQueryObject.Closedown
    Set oQueryObject = Nothing
    
End Sub
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
sample code, vba


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


Renegade Motorhomes - Credit Cards - Mobile Phone - Credit Cards
All times are GMT -6. The time now is 02:21 AM.

Miscellaneous


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Integrated by BBpixel Team 2008 :: jvbPlugin R1012.364.1

SEO by vBSEO 3.2.0 Copyright 2008 Blackbaud User SocietyAd Management by RedTyger
Inactive Reminders By Icora Web Design

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64