• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 22. Visio Automation and Microso... > Querying Access for Visio's Use

Querying Access for Visio's Use

Listing 22.4 shows a deletion process when items are deleted in Visio and they need to have the corresponding record deleted in the Access database.

Listing 22.4. Deleting Database Records by Deleting Shapes in a Visio Diagram

Public g_dbsMyDatabase As DAO.Database
Public g_szDBFileName As String
Public g_bTrack As Boolean
Global Const g_szDefFileName$ = "d:\MyDatabase.mdb"
Global Const g_nFileNotFound% = &HFFFFFFFF
Global Const g_szTableName$ = "Item"
Global Const g_szFieldCost$ = "ItemCost"
Global Const g_szFieldName$ = "ItemName"
Global Const g_szFieldGUID$ = "ItemID"
Global Const g_szUserFileName$ = "User.DBFileName"
Global Const g_szUserTrack$ = "User.Track"
Global Const g_szPropTrack$ = "Prop.Track"
Global Const g_szPropName$ = "Prop.Name"
Global Const g_szPropCost$ = "Prop.Cost"
Global Const g_szIndexName$ = "ItemIndex"
'   Event:  Before Selection Delete
'   Action: Remove any references to the selected shape(s) in the database
Private Sub Document_BeforeSelectionDelete(ByVal vSelection As Visio.IVSelection)
        Dim nCt As Integer                  'Total items in selection
        Dim nCur As Integer                 'Current item in selection
        Dim vShape As Visio.Shape           'A selected shape
        Dim szGUID As String                'The selected shape's GUID
        Dim rstMyRecordset As DAO.Recordset 'A record in the database
        Set rstMyRecordset = g_dbsMyDatabase.OpenRecordset(g_szTableName)
        rstMyRecordset.Index = g_szIndexName
        nCt = vSelection.Count
        'Walk each item in the selection & delete any database references it
        For nCur = 1 To nCt Step 1
               Set vShape = vSelection.Item(nCur)
               szGUID = vShape.UniqueID(visGetGUID)
               If szGUID <> "" Then
               rstMyRecordset.Seek "=", szGUID
               If Not rstMyRecordset.NoMatch Then
                       End If
               End If
End Sub




Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint