home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Software Sampler / Visual_Basic_Software_Sampler_Visual_Basic_Programmers_Journal_June_1996.iso / issues / 03mar96 / code / p50lst1.txt < prev    next >
Text File  |  1996-01-31  |  2KB  |  95 lines

  1. (c) 1996 VISUAL BASIC PROGRAMMER'S JOURNAL
  2. FAWCETTE TECHNICAL PUBLICATIONS
  3.  
  4. FILE NAME: PLMA96L.DOC (Listing for Paul Litwin's Jet Replication article)
  5. ISSUE: MARCH 96
  6. EDITOR: MC
  7. SECTION: FEATURES
  8. STATUS: FIRST EDIT
  9.  
  10.  
  11. Listing 1.
  12. Function glrDbSync(ByVal strFromDb As String, _
  13.     ByVal strToDb As String, _
  14.     Optional ByVal varExchType As Variant) As Boolean
  15.  
  16.     ' Synchronizes two databases
  17.     ' varExchType must be one of following constants:
  18.     '   dbRepImpExpChanges (the default), 
  19.     '   dbRepExportChanges, or
  20.     '   dbRepImportChanges
  21.     ' Returns True if successful; otherwise returns False
  22.  
  23.     On Error GoTo glrDbSync_Err
  24.  
  25.     Dim dbFrom As Database
  26.     glrDbSync = False
  27.  
  28.     Set dbFrom = _
  29.         DBEngine.Workspaces(0).OpenDatabase(strFromDb)
  30.  
  31.     If IsMissing(varExchType) Then _
  32.         varExchType = dbRepImpExpChanges
  33.  
  34.     dbFrom.Synchronize strToDb, varExchType
  35.  
  36.     glrDbSync = True
  37.  
  38. glrDbSync_Exit:
  39.     On Error GoTo 0
  40.     Exit Function
  41.  
  42. glrDbSync_Err:
  43.     Select Case Err
  44.     Case Else
  45.         MsgBox "Error" & Err.Number & ": " & _
  46.             Err.Description, vbOKOnly + _
  47.             vbCritical, "Synchronize Replicas"
  48.     End Select
  49.     Resume glrDbSync_Exit
  50. End Function
  51.  
  52.  
  53. Listing 2.
  54. Private Sub cmdCount_Click()
  55.  
  56.     On Error Resume Next
  57.  
  58.     ' Count the number of updated/new
  59.     ' records in any replicated tables
  60.     ' in this database
  61.  
  62.     Dim lngTotal As Long
  63.     Dim ctlCount As TextBox
  64.     Dim ctlLabel As Label
  65.     Dim db As Database
  66.     Dim tdf As TableDef
  67.     Dim rst As Recordset
  68.  
  69.     Screen.MousePointer = vbHourglass
  70.  
  71.     Set ctlCount = Me!txtCount
  72.     Set ctlLabel = Me!lblCount
  73.     Set db = DBEngine.Workspaces(0).OpenDatabase(txtDb)
  74.     lngTotal = 0
  75.  
  76.     For Each tdf In db.TableDefs
  77.  
  78.         If tdf.Properties!Replicable = "T" Then
  79.             Set rst = db.OpenRecordset(_
  80.                 "SELECT COUNT(*) AS Cnt FROM " & _
  81.                 tdf.Name & _
  82.                 " WHERE [s_Generation]=0;")
  83.             lngTotal = lngTotal + rst!Cnt
  84.         End If
  85.  
  86.     Next tdf
  87.  
  88.     ctlCount = lngTotal
  89.     ctlCount.Enabled = True
  90.     ctlLabel.Enabled = True
  91.  
  92.     Screen.MousePointer = vbDefault
  93.  
  94. End Sub
  95.