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

Sending Data to Access

With the communication channel now open to the database, you can now send data from a Visio diagram to an Access database via the channel using DAO as in Listing 22.3.

Listing 22.3. Sending Data from a Diagram to Acess via DAO

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:  Shape Added
'   Action: Add a record to the database representing this shape
Private Sub Document_ShapeAdded(ByVal vShape As Visio.IVShape)
        Dim vCell As Visio.Cell 'A cell in the new shape
        Dim szGUID As String    'The unique identifier of the new shape
        Dim szName As String    'The name of the item the shape represents
        Dim cyCost As Currency  'The cost of the item the shape represents
        Dim rstMyRecordset As DAO.Recordset 'A record in the tracking table
        'Add a new record
        Set rstMyRecordset = g_dbsMyDatabase.OpenRecordset(g_szTableName)
        'Set the ItemID
        szGUID = vShape.UniqueID(visGetOrMakeGUID)
        rstMyRecordset(g_szFieldGUID) = szGUID
        'Set the ItemName
        Set vCell = vShape.Cells(g_szPropName)
        szName = vCell.Formula
        'Strip quotes
        szName = Mid(szName, 2, (Len(szName) - 2))
        rstMyRecordset(g_szFieldName) = szName
        'Set the ItemCost
        Set vCell = vShape.Cells(g_szPropCost)
        cyCost = vCell.Result(visCurrency)
        rstMyRecordset(g_szFieldCost) = cyCost
End Sub




Not a subscriber?

Start A Free Trial

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