⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 replicate.frm

📁 《VB6数据库开发指南》所有的例程的源码
💻 FRM
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.1#0"; "COMDLG32.OCX"
Begin VB.Form frmReplicate 
   Caption         =   "Replicate Database"
   ClientHeight    =   3345
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6870
   LinkTopic       =   "Form1"
   ScaleHeight     =   3345
   ScaleWidth      =   6870
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdOpenTo 
      Caption         =   "&Browse"
      Height          =   375
      Left            =   5640
      TabIndex        =   7
      Top             =   1200
      Width           =   1095
   End
   Begin VB.CommandButton cmdSynchronize 
      Caption         =   "S&ynchronize"
      Height          =   495
      Left            =   2160
      TabIndex        =   6
      Top             =   1680
      Width           =   1935
   End
   Begin VB.TextBox txtReplicaDbName 
      Height          =   375
      Left            =   0
      TabIndex        =   4
      Top             =   1200
      Width           =   5415
   End
   Begin VB.CommandButton cmdCreateReplica 
      Caption         =   "&Create Replica"
      Height          =   495
      Left            =   0
      TabIndex        =   3
      Top             =   1680
      Width           =   1935
   End
   Begin VB.CommandButton cmdOpenFrom 
      Caption         =   "&Browse"
      Height          =   375
      Left            =   5640
      TabIndex        =   2
      Top             =   480
      Width           =   1095
   End
   Begin MSComDlg.CommonDialog cdOpenFile 
      Left            =   6120
      Top             =   0
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   327680
      Filter          =   "Access Files (*.mdb)|*.mdb"
   End
   Begin VB.TextBox txtDbNameFrom 
      Height          =   375
      Left            =   0
      TabIndex        =   0
      Top             =   480
      Width           =   5415
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "Replica file name:"
      Height          =   195
      Left            =   0
      TabIndex        =   5
      Top             =   960
      Width           =   1260
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "Database to replicate:"
      Height          =   195
      Left            =   0
      TabIndex        =   1
      Top             =   240
      Width           =   1560
   End
End
Attribute VB_Name = "frmReplicate"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub cmdCreateReplica_Click()
' Create a replica from the named database
Dim dbMaster As Database
Dim bContinue As Boolean

    On Error GoTo DbError
    
    ' Open the database in exclusive mode
    Set dbMaster = Workspaces(0).OpenDatabase(txtDbNameFrom.Text, True)
    
    ' Make the database the Design Master
    bContinue = MakeReplicable(dbMaster)
    
    ' Make the replica
    bContinue = CopyReplica(dbMaster, txtReplicaDbName.Text)
    
    dbMaster.Close
    
    Exit Sub
    
DbError:
    MsgBox Err.Description & " From: " & Err.Source _
            & "Number: " & Err.Number
    Exit Sub
    
End Sub
Function CopyReplica(ByRef dbMaster As Database, strRepName As String) _
    As Boolean
' Makes a replica database from the passed master

    On Error GoTo DbError
    
    ' If the target file exists, purge it
    If Dir(strRepName) <> "" Then Kill strRepName
    
    dbMaster.MakeReplica strRepName, "Replica of " & dbMaster.Name
    
    CopyReplica = True
    
    Exit Function
    
DbError:
    MsgBox Err.Description & " From: " & Err.Source _
            & "Number: " & Err.Number
    CopyReplica = False
    Exit Function
    
End Function
Private Sub cmdOpenFrom_Click()
' Open the Replicate from database file
    cdOpenFile.InitDir = App.Path
    cdOpenFile.ShowOpen
    txtDbNameFrom.Text = cdOpenFile.filename
        
End Sub

Function MakeReplicable(ByRef dbMaster As Database) As Boolean
' Makes the passed database replicable
Dim prpReplicable As Property
Dim intIdx As Integer
Dim bFound As Boolean
    
    On Error GoTo DbError
    
    ' Check for existence of the replicable property
    For intIdx = 0 To (dbMaster.Properties.Count - 1)
        If dbMaster.Properties(intIdx).Name = "Replicable" Then
            bFound = True
            Exit For
        End If
    Next
    
    If Not bFound Then
        ' Create the property
        Set prpReplicable = dbMaster.CreateProperty("Replicable", _
                                dbText, "T")
        ' Append it to the collection
        dbMaster.Properties.Append prpReplicable
    End If
    
    ' Set the value of Replicable to true.
    dbMaster.Properties("Replicable").Value = "T"
    
    MakeReplicable = True
    
    Exit Function
    
DbError:
    MsgBox Err.Description & " From: " & Err.Source _
            & "Number: " & Err.Number
    MakeReplicable = False
    Exit Function

End Function

Private Sub cmdOpenTo_Click()
' Open the Replicate to database file
    cdOpenFile.InitDir = App.Path
    cdOpenFile.filename = "Replica.mdb"
    cdOpenFile.ShowOpen
    txtReplicaDbName.Text = cdOpenFile.filename

End Sub

Private Sub cmdSynchronize_Click()

Dim dbMaster As Database
    
    On Error GoTo DbError
    
    ' Open the database in non-exclusive mode
    Set dbMaster = Workspaces(0).OpenDatabase(txtDbNameFrom.Text, False)
    
    ' Synchronize the databases
    dbMaster.Synchronize txtReplicaDbName.Text, _
                    dbRepImpExpChanges
    
    dbMaster.Close
    
    Exit Sub
    
DbError:
    MsgBox Err.Description & " From: " & Err.Source _
            & "Number: " & Err.Number
    Exit Sub

End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -