0% found this document useful (0 votes)
57 views

Back Up Definitions

This document contains VBA code to back up all definitions (queries, tables, and modules) from an Access database. It defines subroutines to back up queries, tables, and modules by exporting their SQL code, structure, and properties to text files stored in specified directories. The code uses objects like QueryDefs, TableDefs, and VBComponents to loop through each definition type and export the relevant definition details to individual text files.

Uploaded by

mts almuttaqin
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

Back Up Definitions

This document contains VBA code to back up all definitions (queries, tables, and modules) from an Access database. It defines subroutines to back up queries, tables, and modules by exporting their SQL code, structure, and properties to text files stored in specified directories. The code uses objects like QueryDefs, TableDefs, and VBComponents to loop through each definition type and export the relevant definition details to individual text files.

Uploaded by

mts almuttaqin
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 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

You might also like