Sei sulla pagina 1di 3

Attribute VB_Name = "BackUpDefinitions"

Option Compare Database


Sub BackUpAllDefinitions()
BackUpAllQueries
BackUpAllTables
BackUpAllModules
End Sub
Sub BackUpAllQueries()
BackUpQueries "P:\DBBackups\ScheduleDataWorking\Query Definitions\"
End Sub
Sub BackUpAllTables()
BackUpTables "P:\DBBackups\ScheduleDataWorking\Table Definitions\"

End Sub
Sub BackUpAllModules()
BackUpModules "P:\DBBackups\ScheduleDataWorking\Modules\"

End Sub
Function BackUpQueries(OutDirectory As String) As Boolean
BackUpQueries = True
On Error GoTo 10
Dim FileName As String
Dim MyDB As Database
Dim QDefs As QueryDefs
Dim QDef As QueryDef
Set MyDB = CurrentDb
Set QDefs = MyDB.QueryDefs

Close #1

For Each QDef In QDefs


'MsgBox (QDef.SQL)
FileName = OutDirectory & QDef.Name & ".txt"
Open FileName For Output As 1
Print #1, QDef.SQL
Close #1
Next QDef

Exit Function
10
BackUpQueries = False

End Function

Function BackUpTables(OutDirectory As String) As Boolean


BackUpTables = True
'On Error GoTo 10
Dim FileName As String
Dim MyDB As Database
Dim TDefs As TableDefs
Dim TDef As TableDef
Dim FieldDef As Field
Dim TIndexes As Indexes
Dim TIndex As Index
Dim TProperties As Properties
Dim TProperty As Property

Set MyDB = CurrentDb


Set TDefs = MyDB.TableDefs
Close #1

For Each TDef In TDefs


'MsgBox (QDef.SQL)
FileName = OutDirectory & TDef.Name & ".txt"
Open FileName For Output As 1

Print #1, " *** Properties *** "


Print #1, " "
'Set TProperties = TDef.Properties
For Each TProperty In TDef.Properties
Print #1, TProperty.Name, TProperty.Type, TProperty.Value
Next TProperty

Print #1, " -------------------"


Print #1, " "

Print #1, "*** Indexes *** "


Print #1, " "

Set TIndexes = TDef.Indexes


On Error Resume Next
For Each TIndex In TIndexes
Print #1, TIndex.Name & ": - Is Primary = " & TIndex.Primary

Next TIndex

Print #1, " "


Print #1, " *** Field Definitions *** "
Print #1, " "

For Each FieldDef In TDef.Fields


Print #1, FieldDef.Name & ": - FieldType = " & FieldDef.Type & _
": - FieldSize = " & FieldDef.Size
Next FieldDef

Close #1
Next TDef

Exit Function
10
BackUpTables = False

End Function

Function BackUpModules(OutDirectory As String) As Boolean

' reference to Microsoft Visual Basic for Applications Extensibility 5.3


BackUpModules = True
On Error GoTo 10
Dim objMyProj As VBProject
Dim objVBComp As VBComponent

Set objMyProj = Application.VBE.ActiveVBProject


For Each objVBComp In objMyProj.VBComponents

objVBComp.Export OutDirectory & objVBComp.Name & ".bas"

Next

Exit Function
10
BackUpModules = False

End Function

Potrebbero piacerti anche