Results 1 to 10 of 10

Sending table to visio, nameing the opened Visio File and quiting Access

  1. #1
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    781

    Sending table to visio, nameing the opened Visio File and quiting Access


    How do I export a an access table into Visio?

    So far I can open Visio. I am working the code to recognize filenameclip as the table to export and name the Visio File as filnameclip. VisioApp.Documents.Add (FileNameClip) gives me an error of "File not found".
    Code:
    Private Sub Open_Visio_Click()
    Dim FName As String
    Dim VisioApp As Object
        
    On Error Resume Next
     
    Set VisioApp = GetObject(, "Visio.Application")
        If VisioApp Is Nothing Then
            Set VisioApp = CreateObject("Visio.Application")
        If VisioApp Is Nothing Then
            MsgBox "Can't connect to Visio"
           Exit Sub
        End If
     End If
     
     On Error GoTo 0
        'VisioApp.Documents.Add FilenameClip 
     
        VisioApp.Visible = True
    
    End Sub
    Last edited by Thompyt; 04-23-2019 at 11:41 AM.

  2. #2
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    3,555
    I have never tried to use Visio from Access but have done similar process opening other Office programs such as Outlook/Word etc.
    You need code to handle the error if Visio isn't running

    You may be able to adapt the code below for your purposes - its adapted from code originally by Daniel Pineault (www.devhut.net)
    First check whether the app is running - if so use GetObject, if not use CreateObject

    Code:
    Function StartOutlook()
    
    On Error GoTo Err_Handler
    
    
        Dim oOutlook        As Object
        Dim sAPPPath        As String
     
        If IsAppRunning("Outlook.Application") = True Then    'Outlook was already running
            Set oOutlook = GetObject(, "Outlook.Application")    'Bind to existing instance of Outlook
        Else    'Could not get instance of Outlook, so create a new one
            sAPPPath = GetAppExePath("outlook.exe")    'determine outlook's installation path
            Shell (sAPPPath)    'start outlook
            Do While Not IsAppRunning("Outlook.Application")
                DoEvents
            Loop
            Set oOutlook = GetObject(, "Outlook.Application")    'Bind to existing instance of Outlook
        End If
     
        '    MsgBox "Outlook Should be running now, let's do something"
        Const olMailItem = 0
        Dim oOutlookMsg     As Object
        Set oOutlookMsg = oOutlook.CreateItem(olMailItem)    'Start a new e-mail message
        oOutlookMsg.display    'Show the message to the user
    
    
    Exit_Handler:
        On Error Resume Next
        Set oOutlook = Nothing
        Exit Function
     
    Err_Handler:
        FormattedMsgBox "Error " & Err.Number & " in StartOutlook procedure :             " & _
            "@" & Err.description & "            @", vbCritical, "Program error"
        Resume Exit_Handler
    End Function
    
    Function IsAppRunning(sApp As String) As Boolean
    
    
    On Error GoTo Err_Handler
        
        Dim oApp As Object
     
        Set oApp = GetObject(, sApp)
        IsAppRunning = True
     
    Exit_Handler:
        On Error Resume Next
        Set oApp = Nothing
        Exit Function
     
    Err_Handler:
        Resume Exit_Handler
        
    End Function
    HTH
    Colin (Mendip Data Systems) : Website, email
    If this has helped, please click the star button and leave a comment

  3. #3
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    781
    Thanks isladogs,
    I have gotten to opening a templated Visio which I am starting to code, or at least trying to. I'm still at the basics. I have still not found out how to import data from a table via VBA into VISIO, or to Export a Table to VISIO.

  4. #4
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    3,555
    I think there is little overlap in expertise between Access & Visio
    Ajax is the only person I know who has tried but IIRC he decided the rewards weren't worth the time and effort needed.
    With luck he will see this thread and respond

    Is there a specialist Visio forum? Or perhaps try the MSDN forums?
    Colin (Mendip Data Systems) : Website, email
    If this has helped, please click the star button and leave a comment

  5. #5
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    781
    isladogs,
    What I have seen so far for VISIO VBA reflects more towards an excel VBA style. The MSDN forums is the only VISIO VBA form I have seen yet. I haven't posted since I was trying to export to VISIO, but I can look at it from the other direction after I open a templated VISO drawing to import the table.

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    6,021
    Can't say I've ever tried this, but what doesn't look right is your reference to filenameClip. If it's a variable, it's not declared. That makes me think you don't have Option Explicit set. If it's the actual name of a table, it's improperly referenced. I also note that you declare a variable but don't use it (FName). Thus there may be underlying issues which are thwarting you.
    - "doesn't work" is no help. Post err msgs and where.
    - Use code tags for code/sql. Implement changes in copies of your database.
    Sometimes I talk to myself - like when I need expert advice.

  7. #7
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    781
    Micron,
    I cheated:
    Code:
    Option Compare Database
    Option Explicit
    Dim strFile As String, strFolder As String, tableName As String, FileNameClip As String
    Code:
    Private Sub Open_Visio_Click()
    Dim VisioApp As Object
    Dim FName As String
    On Error Resume Next
    FName = "C:\Users\Wayne\Desktop\HB_Baseline.vsdm"
     
    Set VisioApp = GetObject(, "Visio.Application")
        If VisioApp Is Nothing Then
            Set VisioApp = CreateObject("Visio.Application")
            If VisioApp Is Nothing Then
                Exit Sub
            End If
        End If
     
     On Error GoTo 0
        
        VisioApp.Documents.Open FName
        VisioApp.Visible = True
     
    End Sub
    I know I need to fix the
    "C:\Users\Wayne\Desktop\HB_Baseline.vsdm" but that's short term. I could not get Visio to open a new macro enabled VISO file named after FileNameClip. With the FName way I could get a new Visio to open and have the Developer and Data tab available.

    Since there will be VBA in the Visio, it might be best to do a direct select and have Visio import the table through VBA. I have a thread open on the MSDN VISIO forum asking just that. I could use strfile
    :
    Code:
       If F.Show Then
            For Each VarItem In F.SelectedItems
               strFile = Dir(VarItem)
                strFolder = Left(VarItem, Len(VarItem) - Len(strFile))
            Next
        End If
    to set the directory.

    I'm not all too sure about how to reference the string variables in another sub. I tried

    VisioApp.Documents.add Update_Table2.FileNameClip and it had issues with the
    Update_Table2

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    6,021
    I don't have Visio on my day-to-day laptop so can't try anything. However, taking this literally
    "I'm not all too sure about how to reference the string variables in another sub"
    I'd venture to say you would not. You'd use a function so that it could return values to a calling sub or function. A sub's variables only exist when that sub is running so I don't see them being visible to another procedure, plus a sub can't return a value.

  9. #9
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    781
    Micron,
    Why can't I use this vice a function?

    Public strFile As String, strFolder As String, tableName As String, FileNameClip As String

    Less characters

  10. #10
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    6,021
    ??
    Did you research what I suggested? I'm afraid your response makes no sense to me.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 05-24-2018, 02:20 AM
  2. Updating a Visio drawing through Access
    By jmejorada360 in forum Import/Export Data
    Replies: 1
    Last Post: 08-10-2012, 12:03 PM
  3. Editing Visio drawing in Form view
    By jmejorada360 in forum Import/Export Data
    Replies: 2
    Last Post: 08-10-2012, 10:15 AM
  4. Replies: 1
    Last Post: 01-05-2012, 02:34 PM
  5. Linking Access Database to Visio
    By annemrosenberg in forum Access
    Replies: 1
    Last Post: 09-22-2011, 01:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Tech Forums: Microsoft Office Forums