clsbackuptable.cls

来自「VB6数据库开发指南》的配套源程序」· CLS 代码 · 共 78 行

CLS
78
字号
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsBackupTable"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit

'local variable(s) to hold property value(s)
Private mvarTableName As String 'local copy
Private mvarDatabaseObject As Object 'local copy
Public Sub DoBackup()
Dim strDbName As String, strSql As String
Dim dbNew As Database

    On Error GoTo DbError
    ' Format a database name from the current time
    strDbName = Format(Now, "Buyyyymmmddhhnnss") & ".mdb"
    strDbName = App.Path & "\" & strDbName
    ' Make sure there isn't already a file with the name of
    ' the new database.
    If Dir(strDbName) <> "" Then Kill strDbName

    ' Create the new database
    Set dbNew = Workspaces(0).CreateDatabase(strDbName, dbLangGeneral)
    ' Create a SQL command string to create the backup
    strSql = "SELECT " & TableName & ".* INTO " _
                & TableName & " IN '" & strDbName _
                & "' FROM " & TableName
    mvarDatabaseObject.Execute strSql
    
    Exit Sub

DbError:
    Err.Raise Err.Number, Err.Source, Err.Description
    Err.Clear
    Exit Sub
    
End Sub

Public Property Set DatabaseObject(ByVal vData As Object)
'used when assigning an Object to the property, on the left side of a Set statement.
'Syntax: Set x.Database = Form1
    Set mvarDatabaseObject = vData
End Property


Public Property Get DatabaseObject() As Object
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.Database
    Set DatabaseObject = mvarDatabaseObject
End Property



Public Property Let TableName(ByVal vData As String)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.TableName = 5
    mvarTableName = vData
End Property

Public Property Get TableName() As String
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.TableName
    TableName = mvarTableName
End Property


⌨️ 快捷键说明

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