Open an SSRS Report from Dynamics GP VBA

This is a really great technique. This article will show how to open an SSRS report from Dynamics GP VBA.

We had to overcome several challenges on the way to do this, I'd like to hear if anyone else has a more elegant technique.

First, we had to get the name of the report server and report from an ini file. Normally I'd store config data in SQL, but I'm trying to stay as light as possible and I don't know of any other way to do this so we use GetPrivateProfileString.

Second, we had to open a browser from VBA; so we used ShellExecute for that.

 The code below is fully commented.

' This funcion is used to open the browser
Private Declare Function ShellExecute _
  Lib "shell32.dll" Alias "ShellExecuteA" ( _
  ByVal hWnd As Long, _
  ByVal Operation As String, _
  ByVal Filename As String, _
  Optional ByVal Parameters As String, _
  Optional ByVal Directory As String, _
  Optional ByVal WindowStyle As Long = vbMinimizedFocus _
  ) As Long
  
'this function is used to get .ini data
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias _
    "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
    ByVal lpKeyName As Any, ByVal lpDefault As String, _
    ByVal lpReturnedString As String, ByVal nSize As Long, _
    ByVal lpFileName As String) As Long
  
  
Private Sub RMA_Changed()
    Dim strUrl As String
    Dim strRMA As String
    Dim strType As String
      
    strRMA = Me.RMANumber
    strType = "1"
      
    If strRMA = "" Then
        Exit Sub
    End If
      
    'get the current directory
    strUrl = CurDir
    'read the ini file and get the SSRS report path
    strUrl = GetReportPath("DD", "RMAReportPath", strUrl & "\DD.ini")
      
    'add the report params to the URL
    strUrl = strUrl & "&RETURNDOCID=" & strRMA & "&Return_Record_Type=" & strType
  
    'open the browser
    Dim lSuccess As Long
    lSuccess = ShellExecute(0, "Open", strUrl)
  
End Sub
Function GetReportPath(ByVal strSectionName As String, ByVal strEntry As String, ByVal strIniPath As String) As String
    'this funtion returns data from an ini file
    Dim X As Long
    Dim sSection As String, sEntry As String, sDefault As String
    Dim sRetBuf As String, iLenBuf As Integer, sFileName As String
    Dim sValue As String
      
    On Error GoTo ErrGetSectionentry
    sSection = strSectionName
    sEntry = strEntry
    sDefault = ""
    sRetBuf = Strings.String$(256, 0) '256 null characters
    iLenBuf = Len(sRetBuf$)
    sFileName = strIniPath
    X = GetPrivateProfileString(sSection, sEntry, "", sRetBuf, iLenBuf, sFileName)
    sValue = Strings.Trim(Strings.Left$(sRetBuf, X))
      
    If sValue <> "" Then
        GetReportPath = sValue
    Else
        GetReportPath = vbNullChar
    End If
      
ErrGetSectionentry:
    If Err <> 0 Then
    Err.Clear
    Resume Next
    End If
  
  
End Function
  
  

RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences