Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine if Application is Installed 1

Status
Not open for further replies.

Savil

Programmer
Apr 28, 2003
333
EU
Hi all
I have written a procedure in Access 97 that programatically creates an organisation chart in Visio 2002 which works great. Some of the machines at work do not have visio installed so I would like to disable the create chart button. How can I check if Visio is installed?

Thanks in advance
 
The following function will return a value of True if Visio is installed, and False if it is not:
Code:
Public Function IsVisioInstalled() As Boolean
On Error Resume Next

    Dim vApp As Object

    Set vApp = CreateObject("Visio.Application")
    If Err.Number = 0 Then
        IsVisioInstalled = True
        vApp.Quit
        Set vApp = Nothing
    Else
        Err.Clear
    End If

End Function
 
Excellent, Thanks ByteMyzer I never thought tojust trap the error.
 
I am curious about interfacing with Visio. Keeping it simple, I was thinking of creating a seating chart based on users that exist in an Access table. Can you walk me thru the steps you used to create your chart? Thanks.
 
Hi evalesthy
I have only ever dealt with org charts due to the project i am working on and using the orgCwiz addon you can create an org chart programatically. thinking about it though you probably could do a seating chart by creating an org chart, deleting the connectors and enveloping the relevant shapes in a box to indicate tables. To start in your table or query you need a minimum of two columns in your case I would have the persons name (This has to be unique) and the table number. This indicates a person and their manager. The manager also has to have an entry as a person aswell. If it does'nt then the wizard will fail. Here is an example

Name (Person) Table (Manager)
---------------------------
John Smith Table 1
Tom Jones Table 2
Jane Doe Table 1
John Doe Table 1
Eric Fisher Table 2
Table 1 Seating Chart
Table 2 Seating Chart
Seating Chart Seating Chart (The top manager is his own manager)

This arrangement will provide a chart like

Code:
                       Seating Chart
                             |
                             |
        --------------------------------------------
       |                                            |
       |                                            |
   Table 1                                       Table 2
       |                                            |
   --------------------------        ----------------------
   |             |           |      |                     |
John Smith   John Doe   Jane Doe  Tom Jones      Eric Fisher

Here is the VBA code you need

Code:
Public Sub CreateOrgChart()

On Error GoTo CreateOrgChart_Err


    Const ORGANIZATION_CHART_WIZARD As String = "OrgCWiz"
    
    Dim vsoApp          As Visio.Application
    Dim vsoAddOn        As Visio.Addon
    Dim strCommand      As String
    Dim strCommandPart  As String
    
    Dim strQuery As String
    
    strQuery = "qryOrgChart"
    
    ' Create an instance of Visio.
    Set vsoApp = New Visio.Application
    
    
    ' Get a reference to the Organization Chart Wizard add-on.
    Set vsoAddOn = vsoApp.Addons.Item(ORGANIZATION_CHART_WIZARD)
    
    ' Initialize the wizard and prepare it to accept a
    ' series of arguments.
    strCommand = "/S-INIT"
    vsoAddOn.Run strCommand
    
    strCommand = "/S-ARGSTR "
    
    ' Specify that the org chart information will be from Microsoft Access.
    strCommandPart = "/DATASOURCE=VisioConnectFile.dsn,TABLE=" & strQuery & "," & ShowCurrentFolder & ""
    
    vsoAddOn.Run strCommand & strCommandPart
    
    strCommandPart = "/UNIQUEID-FIELD=" _
        & StringToFormulaForString("Name")
    vsoAddOn.Run strCommand & strCommandPart
    
    strCommandPart = "/NAME-FIELD=" _
        & StringToFormulaForString("Name")
    vsoAddOn.Run strCommand & strCommandPart
    
    strCommandPart = "/MANAGER-FIELD=" _
        & StringToFormulaForString("Table")
    vsoAddOn.Run strCommand & strCommandPart
    
    strCommandPart = "/DISPLAY-FIELDS=Name, Table"
    vsoAddOn.Run strCommand & strCommandPart
    
    strCommandPart = "/CUSTOM-PROPERTY-FIELDS=Name, Table"
    vsoAddOn.Run strCommand & strCommandPart
    
    'This tells visio to put the chart on one page
    strCommandPart = "/PAGES=Table"
    strCommand = strCommand & strCommandPart
    
    strCommand = strCommand & "/PAGENAME=TablePlan"
    vsoAddOn.Run strCommand
    
    ' Begin creating the org chart.
    strCommand = "/S-RUN "
    vsoAddOn.Run strCommand
    
    
     
    Exit Sub
    
CreateOrgChart_Err:
    MsgBox err.Description
    
End Sub
----------------------------------------------------------------------

Public Function StringToFormulaForString(strIn As String) As String
    
' StringToFormulaForString
'
' Abstract - Convert the input string to a Visio string by
' replacing each 'double quote'(") with a 'double double
' quote'("") and adding a ("") around the entire string.
'
' Parameters strIn
' Input string that will to be converted to Visio String
'
' Return Value  Returns the converted Visio string

    Dim strResult As String
    Dim intCtr As Integer
    
    On Error GoTo StringToFormulaForString_Err
    
    strResult = strIn

    'The original code that comes from Microsoft is based on VB
    'and uses the replace function. in Access 97 you don't have that luxury
    'and have to use the mid statement. When looping through a string to
    'to find a character and then replace it with itself twice it gets messy
    'thats why I convert it to (^) first and then (")
    
    'Changes all " to ^^
    For intCtr = 1 To Len(strResult)
        If Mid(strResult, intCtr, 1) = Chr(34) Then
            Mid(strResult, intCtr, 2) = Chr(94) & Chr(94)
        End If
    Next
    'Changes all ^ to "
    For intCtr = 1 To Len(strResult)
        If Mid(strResult, intCtr, 1) = Chr(94) Then
            Mid(strResult, intCtr, 2) = Chr(34)
        End If
    Next
    
    ' Add ("") around the whole string.
    strResult = Chr(34) & strResult & Chr(34)
    
    StringToFormulaForString = strResult

    Exit Function
    
StringToFormulaForString_Err:
    MsgBox err.Description
    
End Function
----------------------------------------------------------------------

Public Function ShowCurrentFolder()

'Returns the true path and name of current database

ShowCurrentFolder = left(CurrentDb.name, InStr(CurrentDb.name, Dir(CurrentDb.name)) - 1) _
& Mid(CurrentDb.name, InStr(CurrentDb.name, Dir(CurrentDb.name)), _
& (Len(CurrentDb.name) - InStr(CurrentDb.name, Dir(CurrentDb.name)) + 1))

End Function

I hope this is of some use to you, it works for me

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top