Visio Guy

Visio Discussions => Programming & Code => Topic started by: vanlanjl on December 09, 2009, 07:27:13 PM

Title: Connecting web/visio to SQL Database
Post by: vanlanjl on December 09, 2009, 07:27:13 PM
I have created an extensive Network toppolgy through Visio. I have collected all network device data and complied it into a SQL database. I then have linked the Visio to the Database. So each shape shows the correct data for it. My question is, will i need to write a code to make sure it is updated. Or will it automatically update if changes are made in the database since it is linked to it?
Title: Re: Connecting web/visio to SQL Database
Post by: Jumpy on December 09, 2009, 08:23:41 PM
You need a VBA Sub that starts everytime you open the drawing to refresh the Link.
If you want to refresh a Link when the drawing is open, you can do it manually or use a second similar VBA Sub to do this on command.
Title: Re: Connecting web/visio to SQL Database
Post by: vanlanjl on December 09, 2009, 08:35:19 PM
Where could i find directions on setting this up? would this work for the html version?
Title: Re: Connecting web/visio to SQL Database
Post by: Visio Guy on December 10, 2009, 04:43:39 AM
Hi Guys,

Here's an article that will help with getting code to run when a document opens: Run VBA Code When Documents Open (http://www.visguy.com/2007/05/25/run-vba-code-when-documents-open/)
Title: Re: Connecting web/visio to SQL Database
Post by: Visio Guy on December 10, 2009, 04:45:47 AM
Which method did you use to link shapes to the database? There are several routes in Visio. Also, which version of Visio are you using?
Title: Re: Connecting web/visio to SQL Database
Post by: vanlanjl on December 10, 2009, 07:42:14 PM
I am using Visio 2007 pro

A sfar as linking the data to the shapes. I have imported the databse.

I go to "Data" on the menu bar,
Link data to shapes,
Microsoft SQL Server database
then type in the sql server name and select the tables that i want.
it loads the tables
i then find the record i want and drag it to the shape i want.
all done
Title: Re: Connecting web/visio to SQL Database
Post by: Jumpy on December 10, 2009, 09:40:45 PM
Than it could go like this:

Public Sub Refresh_Example()

    Dim vsoDataRecordset As Visio.DataRecordset
    Dim intCount As Integer

    intCount = ThisDocument.DataRecordsets.Count
    Set vsoDataRecordset = ThisDocument.DataRecordsets(intCount)
    vsoDataRecordset.Refresh

End Sub

Taken form here:
http://msdn.microsoft.com/en-us/library/ms427208.aspx