There was a question recently on Blackbus asking how to open a link from a constituent record. For example if you had an external system that uses constituent ids to find individuals it would be very useful to be able to open a web page from the constituent window by pressing the macro button and going to the web page that is specific for the constituent. This requires the VBA module. Here is how it is done:
In the VBA IDE paste the following code first in the System_Macros file.
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _ (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _ ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long Public Sub OpenLink(oRecord As IBBDataObject) Dim oConstit As CRecord Dim sConstitId As String If TypeOf oRecord Is CRecord Then Set oConstit = oRecord sConstitId = oConstit.Fields(RECORDS_fld_CONSTITUENT_ID) 'This is of course a dummy link and will not lead to anything other than a "Not found" page on my site. GoURL "http://www.zeidman.info/constituent.php?id=" & sConstitId End If End Sub Public Sub GoURL(Destination As Variant) On Error GoTo ErrHandler Dim hwnd As Long Dim conSwNormal As Long 'check and see if there is a valid link If Destination = "" Then 'A link was not entered Err.Raise 100 End If 'execute the link ShellExecute hwnd, "open", Destination, vbNullString, vbNullString, conSwNormal Exit Sub ErrHandler: MsgBox "Could not open URL " & Chr(10) & Destination, vbCritical, "Hyperlink" End Sub
This is relatively straight forward piece of code and opens up the link in a browser window. The macro OpenLink calls the GoURL procedure. This procedure calls the Windows API routine for opening a document in Windows using the registered application. This code could as easily be used for opening an image or a Word document as a link.