• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

bVisual

  • Home
  • Services
    • How Visio smartness can help your business
    • Visio visual in Power BI
    • Visio Consulting Services
    • Visio Bureau Services
    • Visio Training and Support Services
  • Products
    • Visio Shape Report Converter
    • SS Plus
    • LayerManager
    • visViewer
    • Metro Icons
    • Rules Tools for Visio
    • The Visio 2010 Sessions App
    • Multi-Language Text for Visio
    • Document Imager for Visio
    • multiSelect for Visio
    • pdSelect for Visio
  • Case Studies
    • Case studies overview
    • Using Visio in Education for GIS
    • Visualizing Construction Project Schedules
    • Visio Online Business Process Mapping
    • Nexans Visio Template
    • CNEE Projects, WorldCom
    • Chase Manhattan Bank
  • News
    • Recent news
    • News archive
  • Resources
    • Articles➡
      • ShapeSheet Functions A-Z
      • Comparing Visio for the Web and Desktop
      • Customising Visio Shapes for the Web App
      • Key differences between the Visio desktop and web apps
      • Using the Visio Data Visualizer in Excel
      • Using Visio in Teams
      • Creating Visio Tabs and Apps for Teams with SharePoint Framework (SPFx)
      • Designing Power Automate Flows with Microsoft Visio
      • Innovative uses of Visio Lists
    • Webcasts ➡
      • Visio in Organizations
      • My session and other Visio sessions at MSIgnite 2019
      • Power up your Visio diagrams
      • Vision up your Visio diagrams
      • The Visio 2010 MVP Sessions
    • Visio Web Learning Resources
    • Books➡
      • Visualize Complex Processes with Microsoft Visio
      • Mastering Data Visualization with Microsoft Visio
      • Microsoft Visio Business Process Diagramming and Validation
      • Visualizing Information with Microsoft Visio
  • Blog
    • Browse blog articles
    • Visio Power BI articles
    • Visio for Web articles
    • A history of messaging and encryption
  • About us
    • About bVisual
    • Testimonials
    • Bio of David Parker
    • Contact Us
    • Website Privacy Policy
    • Website terms and conditions
    • Ariba Network
You are here: Home / Visio / Visio 2013 / Linking Data to Visio with SQL Server Stored Procedures

Published on April 29, 2015 by David Parker

Linking Data to Visio with SQL Server Stored Procedures

Visio Professional has the ability to link to various data sources, and one of the most popular is SQL Server. The DATA\Link Data to Shapes … function will present a UI to choose from a table or view, but does not provide any stored procedures. Therefore, this article present a VBA macro that demonstrates how a stored procedure can be added as a refreshable data recordset in Visio.

This macro uses the uspGetManagerEmployees procedure from the AdventureWorks sample database ( see https://msftdbprodsamples.codeplex.com/releases ). It expects one integer parameter, and returns a list of employees for a given manager’s business entity id. You will need to enter your own Data Source and Initial Catalog values.

Public Sub AddOrRefreshFromStoredProc() 
On Error GoTo errHandler
Dim dds As Visio.DataRecordset  'The data recordset
Dim ary() As String         'Array to hold the p key columns
Dim SQLConnStr As String    'The connection string
Dim SQLCommStr As String    'The Command string
Dim datasetName As String   'The dataset name
           
    SQLConnStr = "Provider=SQLOLEDB.1;" & _
        "Integrated Security=SSPI;Persist Security Info=True;" & _
        "Initial Catalog=AdventureWorks2014;" & _
        "Data Source=ARUBA\SQLExpress2014x8;" & _
        "Use Procedure for Prepare=1;"
    SQLCommStr = "EXEC dbo.uspGetManagerEmployees "
      
Dim busEntity As Variant
    busEntity = InputBox("Which business entity to you want to retrieve for?", SQLCommStr, 2)
    If IsNumeric(busEntity) = False Then
        MsgBox "You must enter an integer", vbCritical, SQLCommStr
        GoTo exitHere
    End If
    SQLCommStr = SQLCommStr & CStr(busEntity)
    ary() = Split("BusinessEntityID", ";")
    datasetName = "uspGetManagerEmployees for " & CStr(busEntity)
    'Check if the recordset exists already 
    For Each dds In Visio.ActiveDocument.DataRecordsets
        If dds.CommandString = SQLCommStr Then
            dds.Refresh
            GoTo exitHere
        End If
    Next
   
    Set dds = Visio.ActiveDocument.DataRecordsets.Add( _
           SQLConnStr, SQLCommStr, _
           VisDataRecordsetAddOptions.visDataRecordsetDelayQuery, _
           datasetName)
    dds.SetPrimaryKey VisPrimaryKeySettings.visKeySingle, ary() 
    dds.Refresh
    Visio.ActiveWindow.Windows.ItemFromID( _ 
        visWinIDExternalData).Visible = True
exitHere: 
    Exit Sub
errHandler:
    MsgBox Err.Description
    Resume exitHere
End Sub

The macro will simply ask for the stored procedure parameter to be entered:

image

The stored procedure will then be executed an a data recordset will be added to the document.

image

This recordset can be refreshed in the normal manner, or by re-running the macro with the same parameter.

Related

Filed Under: SQL Server, Visio 2013 Tagged With: Link Data to Shapes, SQL

About David Parker

David Parker has 25 years' experience of providing data visualization solutions to companies around the globe. He is a Microsoft MVP and Visio expert.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

  • LinkedIn
  • Twitter

Recent Posts

  • Fixing dimensions of 2D shapes
  • Merging Linked Data from Similar Tables
  • Smart Radio Buttons and Check Boxes in Visio
  • Using Button Face Ids in Visio
  • Grid Snapping Revisited

Categories

Tags

Accessibility Add-Ins Connectors Containers Data Export Data Graphics Data Import Data Visualizer Educational Excel GraphDatabase Hyperlinks Icon Sets JavaScript LayerManager Layers Legend Link Data to Shapes Lists MSIgnite MVP Office365 Org Chart PowerApps PowerBI PowerQuery Processes Setup and Deployment Shape Data Shape Design ShapeSheet ShapeSheet Functions SharePoint 2013 SQL Teams Validation VBA Video Visio Visio 2007 Visio for the Web Visio Online Visio Services Visio Viewer Webinar

Footer

bVisual Profile

The UK-based independent Visio consultancy with a worldwide reach. We have over 25 years experience of providing data visualization solutions to companies around the globe.

Learn more about bVisual

  • Amazon
  • E-mail
  • Facebook
  • LinkedIn
  • Twitter
  • YouTube

Search this website

Recent posts

  • Fixing dimensions of 2D shapes
  • Merging Linked Data from Similar Tables
  • Smart Radio Buttons and Check Boxes in Visio
  • Using Button Face Ids in Visio
  • Grid Snapping Revisited

Copyright © 2025 · Executive Pro on Genesis Framework · WordPress · Log in