Notices


Reply
 
LinkBack Thread Tools Display Modes

Old 09-23-2007, 07:35 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

VBA Help: Script to Display Google Map

Hi everyone,

I'm relatively new to RE/VBA and have created a little script that shows a google map for a constituent's primary address as a learning exercise.

I've pasted the code below (feel free to use it or provide feedback) and have a couple of questions about how to make it available in the application:

Q 1. I would like users to be able to run this script when they are viewing a constituent. How do you test to see what the user's 'currently active constituent record' is in RE? I can't seem to find anything on this in the help files.

Q 2. I would like users to be able to run this script by clicking a button (currently they would have to run it by using Tools/Run Macro/System Macros/ScriptName) - is there an easy way to run the script from a toolbar button?


NB We are using RE 7.5 - but I imagine it should work for all versions.

Here is the code:

Code:
Option Explicit

Public Sub DisplayGoogleMap()

    Dim ReService As REServices
    Set ReService = New REServices
    ReService.Init REApplication.SessionContext ' Init the ServiceObject for the search screen
    
    'Create an instance of an IBBSearchScreen object and create the service object bbsoSearchScreen
    Dim oSearch As IBBSearchScreen
    Set oSearch = ReService.CreateServiceObject(bbsoSearchScreen)
    
    'Create a CRecord object to hold the returned constituent
    Dim oRecord As CRecord
    Set oRecord = New CRecord
    oRecord.Init REApplication.SessionContext

    With oSearch
        .Init REApplication.SessionContext
        .AddSearchType SEARCH_CONSTITUENT 'Look only for constituents
        .ShowSearchForm

        If .SelectedID > 0 Then
            Set oRecord = .SelectedDataObject
            
         
            ' Get the preferred address
            Dim strAddress As String
            
            strAddress = oRecord.PreferredAddress.Fields(CONSTIT_ADDRESS_fld_ADDRESS_BLOCK)
            If InStr(strAddress, "/") > 0 Then
                strAddress = Right(strAddress, Len(strAddress) - InStr(strAddress, "/"))
            End If
                        
            strAddress = strAddress & ", " _
            & oRecord.PreferredAddress.Fields(CONSTIT_ADDRESS_fld_CITY) & " " _
            & oRecord.PreferredAddress.Fields(CONSTIT_ADDRESS_fld_STATE) & " " _
            & oRecord.PreferredAddress.Fields(CONSTIT_ADDRESS_fld_POST_CODE) & " " _
            & oRecord.PreferredAddress.Fields(CONSTIT_ADDRESS_fld_COUNTRY)

            ' Open the URL in IE
            Dim IE As Object
            Set IE = CreateObject("InternetExplorer.application")
            IE.Visible = True
            
            ' Format example = http://maps.google.com/maps?q=13%20Elizabeth%20St%20+Artarmon+New%20South%20Wales+1570+Australia
            IE.Navigate "http://maps.google.com/maps?q=" & strAddress
          End If
    End With
                
    'Clean up the object references
    oSearch.CloseDown
    Set oSearch = Nothing

    oRecord.CloseDown
    Set oRecord = Nothing
    
    ReService.CloseDown
    Set ReService = Nothing
    
End Sub
Thankyou!

Mobius
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

Old 09-24-2007, 03:52 AM   #2 (permalink)
Likes to customize RE!

DavidZ's Avatar

Join Date: Jul 2006
Location: London, UK
Posts: 335
Rep Power: 3 DavidZ is on a distinguished road

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

Hi Mobius,

Welcome to the group!

The best way for a user to run the script on a constituent by constituent basis is to write the script that accepts the IBBDataObject as a single parameter. If you then put this in your user or system macros it will appear in the macro button drop down and you can run it from there per constituent.
Code:
 
 
Public Sub ShowMap(oRecord As IBBDataObject)
 
     If TypeOf oRecord Is CRecord Then
 
         ........
 
    End If
 
End Sub
When you upgrade to 7.81 you can also implement the IBBMacroProperties interface and select which objects will see this macro and what the name of it is in the drop down and which icon to show (although the last time I tested this it didn't work properly but it may have been fixed by now)

Quote:
How do you test to see what the user's 'currently active constituent record' is in RE?
I am not quite sure what you mean by this. As you can have many constituents open at the same time there is no current as such. You have to simply develop code that works on the current constituent (as the above example shows) or use the active objects in the VBA environment to capture events for the current object.

David
__________________
David Zeidman
Zeidman Development
http://www.zeidman.info

Check out my RE API blog
http://www.re-decoded.com


Last edited by DavidZ; 09-24-2007 at 03:56 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

Old 09-25-2007, 07:13 PM   #3 (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

Thankyou!

Hi David,

That was very helpful - picking up the IBBDataObject gave me the current constituent I was after in the second question. My code is now located in the System_Macro module and our staff can use the 'magic macro button' to view maps for their constituents!

I have posted the updated code below if anyone wants to use it:

PS I ended up having to eliminate the 'clean up' bit for the oConstit as I was getting an error about needing to init the oConstit record when I went to close the constituent. Not sure why this was happening!

Code:
Public Sub ShowGoogleMap(oRecord As IBBDataObject)
' Shows a google map of the constituent's preferred address
If TypeOf oRecord Is CRecord Then
    Dim oConstit As CRecord
    Set oConstit = New CRecord
    oConstit.Init REApplication.SessionContext

    Set oConstit = oRecord

    Dim strAddress As String
    
    strAddress = oConstit.PreferredAddress.Fields(CONSTIT_ADDRESS_fld_ADDRESS_BLOCK) & ", "
    
    ' Tidy up address
    If InStr(strAddress, "/") > 0 Then
        strAddress = Right(strAddress, Len(strAddress) - InStr(strAddress, "/"))
    ElseIf InStr(strAddress, "PO Box") > 0 Then
        strAddress = ""
    End If
    
    strAddress = strAddress & oConstit.PreferredAddress.Fields(CONSTIT_ADDRESS_fld_CITY) & " " _
    & oConstit.PreferredAddress.Fields(CONSTIT_ADDRESS_fld_STATE) & " " _
    & oConstit.PreferredAddress.Fields(CONSTIT_ADDRESS_fld_POST_CODE) & " " _
    & oConstit.PreferredAddress.Fields(CONSTIT_ADDRESS_fld_COUNTRY)
    
    ' Open the URL in IE
    Dim IE As Object
    Set IE = CreateObject("InternetExplorer.application")
    IE.Visible = True
    IE.Navigate "http://maps.google.com/maps?q=" & strAddress

End If
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

Old 09-26-2007, 08:30 AM   #4 (permalink)
o o o o o o o o o o o o o o o o o o

JeffMon's Avatar

Join Date: Aug 2006
Location: Charleston, SC
Posts: 54
Rep Power: 3 JeffMon is on a distinguished road

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

Quote:
I ended up having to eliminate the 'clean up' bit for the oConstit as I was getting an error about needing to init the oConstit
Hi Mobius,

The general rule of thumb with RE objects is "If you didn't init it, don't close it down". With data object macros (the type of macro you created), RE hands you the object fully init'ed (and in-use) and it expects you to hand it back in the same init'ed state. If you close it down and then hand it back, RE will fail when it goes to use the object. There are a few exceptions to this rule, but for data object macros you can use it pretty reliably.

You are instantiating and init'ing a new constituent object, then you set the object to the constit that was passed in, effectively blowing away the the object you just instantiated. You can safely remove these two lines of code near the beginning:

Code:
    Set oConstit = New CRecord
    oConstit.Init REApplication.SessionContext
Jeff
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
google maps, 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


Cheap Electricity - Credit Cards - Mobile Phones - Internet Marketing
All times are GMT -6. The time now is 10:16 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