VBA and Visio

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Hulting
    New Member
    • Dec 2010
    • 13

    VBA and Visio

    I have code in Visio that reads a access table, and creates a new tab for each item in the field. I want to have the code look for existing tabs and move to the next one if the tab exists. I guess it would be a nested loop but cannot seem to get it to work. Any help would be greatly appreciated.

    Andrew

    Code:
    Public Function fnImportText()
    Dim objAccess As AccessObject
    Dim Accapp As Access.Application
    Dim fso As Scripting.FileSystemObject
    Dim rst As DAO.Recordset
    Dim db As Database
    Dim dbFileName As String
    Dim PageObj As Visio.Page
    Dim pageNameStr  As String
    
    Set Accapp = New Access.Application
    Accapp.OpenCurrentDatabase ("extract.mdb")
    Set db = CurrentDb()
    Set rst = db.OpenRecordset("DatabaseList", dbOpenSnapshot)
    
    Do While Not rst.EOF
    dbFileName = rst("Name")
    'MsgBox (dbFileName) 
                    Set PagObj = ThisDocument.Pages.Add
                    Do While PagObj.Name <> dbFileName
                    PageObj.Name = dbFileName
                    
                    MsgBox ("Page Exists")
                    Exit Do
                    rst.MoveNext
                    Loop
                    Loop
                    
    
    'rst.Close
    
    
    End Function
  • Andrew Hulting
    New Member
    • Dec 2010
    • 13

    #2
    fixed

    Code:
    Do While Not rst.EOF
    'MsgBox (dbFileName) ' test returns database name
            For Each PagObj In ActiveDocument.Pages
                If PagObj.Name <> rst!Name Then
                ElseIf PagObj.Name = rst!Name Then
                rst.MoveNext
                End If
            Next
                Set PagObj = ThisDocument.Pages.Add
                    PagObj.Name = rst!Name 'dbFileName
            Loop
    
    rst.Close

    Comment

    Working...