Permalink
Browse files

db.QueryDefs.count, isn't the same number as actual exported queries.…

… Using obj_count instead for all exports.

Added obj_count to import, bit pointless knowing how many objects were export if you can't tally the number imported.
Close all open forms and reports before importing.
  • Loading branch information...
1 parent 4c8a3fb commit aa3a48856df694331aa68f1d2785a79722b14151 @matonb matonb committed Apr 5, 2013
Showing with 84 additions and 35 deletions.
  1. +82 −35 AppCodeImportExport.bas
  2. +2 −0 CHANGELOG.md
View
@@ -61,7 +61,7 @@ End Type
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateTrue = -1, TristateFalse = 0, TristateUseDefault = -2
-Const AggressiveSanitize = 0
+Const AggressiveSanitize = 1
' --------------------------------
' Module variables
@@ -72,6 +72,23 @@ Private UsingUcs2_Result As String
' --------------------------------
' Beginning of main functions of this module
' --------------------------------
+Private Function CloseFormsReports()
+'
+'Close all open forms
+
+ On Error GoTo ErrorHandler
+ Do While Forms.count > 0
+ DoCmd.Close acForm, Forms(0).Name
+ Loop
+ Do While Reports.count > 0
+ DoCmd.Close acReport, Reports(0).Name
+ Loop
+
+ Exit Function
+ErrorHandler:
+ Debug.Print "AppCodeImportExport.CloseFormsReports: Error #" & Err.Number & vbCrLf & Err.description
+
+End Function
Private Function BinOpen(file_path As String, mode As String) As BinFile
Dim f As BinFile
@@ -170,7 +187,10 @@ End Sub
Private Sub ImportObject(obj_type_num As Integer, obj_name As String, file_path As String, _
Optional Ucs2Convert As Boolean = False)
-
+'
+' Been getting "reserved" errors if a form is open....
+ CloseFormsReports
+
If Ucs2Convert Then
ConvertUtf8Ucs2 file_path, TempFile()
Application.LoadFromText obj_type_num, obj_name, TempFile()
@@ -408,7 +428,12 @@ Public Sub ExportAllSource()
Dim obj_type_num As Integer
Dim ucs2 As Boolean
Dim tblName As Variant
+ Dim obj_count As Integer
+ '
+ ' Been getting "reserved" errors if a form was open.
+ CloseFormsReports
+
Set db = CurrentDb
source_path = ProjectPath() & "source\"
@@ -419,27 +444,28 @@ Public Sub ExportAllSource()
obj_path = source_path & "queries\"
ClearTextFilesFromDir obj_path, "bas"
If (db.QueryDefs.count > 0) Then
+ obj_count = 0
Debug.Print "Exporting queries "; Tab(20);
For Each qry In db.QueryDefs
If Left(qry.Name, 1) <> "~" Then
ExportObject acQuery, qry.Name, obj_path & qry.Name & ".bas", UsingUcs2()
+ obj_count = obj_count + 1
If (AggressiveSanitize > 0) Then: SanitizeTextFiles obj_path, "bas"
End If
Next
- Debug.Print "[" & db.QueryDefs.count & "]"
+ Debug.Print "[" & obj_count & "]"
End If
obj_path = source_path & "tables\"
ClearTextFilesFromDir obj_path, "txt"
If (Len(Replace(INCLUDE_TABLES, " ", "")) > 0) Then
- Dim count As Integer
- count = 0
+ obj_count = 0
Debug.Print "Exporting tables"; Tab(20);
For Each tblName In Split(INCLUDE_TABLES, ",")
ExportTable CStr(tblName), obj_path
- count = count + 1
+ obj_count = obj_count + 1
Next
- Debug.Print "[" & count & "]"
+ Debug.Print "[" & obj_count & "]"
End If
For Each obj_type In Split( _
@@ -459,6 +485,7 @@ Public Sub ExportAllSource()
' Export objects (if there are any).
If (db.Containers(obj_type_name).Documents.count > 0) Then
Debug.Print "Exporting " & obj_type_label; Tab(20);
+ obj_count = 0
For Each doc In db.Containers(obj_type_name).Documents
If Left(doc.Name, 1) <> "~" Then
If obj_type_label = "modules" Then
@@ -467,9 +494,10 @@ Public Sub ExportAllSource()
ucs2 = UsingUcs2()
End If
ExportObject obj_type_num, doc.Name, obj_path & doc.Name & ".bas", ucs2
+ obj_count = obj_count + 1
End If
Next
- Debug.Print "[" & db.Containers(obj_type_name).Documents.count & "]"
+ Debug.Print "[" & obj_count & "]"
If obj_type_label <> "modules" Then
SanitizeTextFiles obj_path, "bas"
End If
@@ -498,6 +526,11 @@ Public Sub ImportAllSource()
Dim FileName As String
Dim obj_name As String
Dim ucs2 As Boolean
+ Dim obj_count As Integer
+
+ '
+ ' Getting "reserved" error if a form was open during import.
+ CloseFormsReports
Set db = CurrentDb
Set fso = CreateObject("Scripting.FileSystemObject")
@@ -512,23 +545,32 @@ Public Sub ImportAllSource()
obj_path = source_path & "queries\"
FileName = Dir(obj_path & "*.bas")
- If Len(FileName) > 0 Then: Debug.Print "Importing queries..."
- Do Until Len(FileName) = 0
- obj_name = Mid(FileName, 1, InStrRev(FileName, ".") - 1)
- ImportObject acQuery, obj_name, obj_path & FileName, UsingUcs2()
- FileName = Dir()
- Loop
-
- '' read in table values
+ If Len(FileName) > 0 Then
+ Debug.Print "Importing queries"; Tab(20);
+ obj_count = 0
+ Do Until Len(FileName) = 0
+ obj_name = Mid(FileName, 1, InStrRev(FileName, ".") - 1)
+ ImportObject acQuery, obj_name, obj_path & FileName, UsingUcs2()
+ obj_count = obj_count + 1
+ FileName = Dir()
+ Loop
+ Debug.Print "[" & obj_count & "]"
+ End If
+ '
+ ' read in table values
obj_path = source_path & "tables\"
FileName = Dir(obj_path & "*.txt")
- If Len(FileName) > 0 Then: Debug.Print "Importing tables..."
- Do Until Len(FileName) = 0
- obj_name = Mid(FileName, 1, InStrRev(FileName, ".") - 1)
- ImportTable CStr(obj_name), obj_path
- FileName = Dir()
- Loop
-
+ If Len(FileName) > 0 Then
+ Debug.Print "Importing tables"; Tab(20);
+ obj_count = 0
+ Do Until Len(FileName) = 0
+ obj_name = Mid(FileName, 1, InStrRev(FileName, ".") - 1)
+ ImportTable CStr(obj_name), obj_path
+ obj_count = obj_count + 1
+ FileName = Dir()
+ Loop
+ Debug.Print "[" & obj_count & "]"
+ End If
For Each obj_type In Split( _
"forms|" & acForm & "," & _
"reports|" & acReport & "," & _
@@ -541,19 +583,24 @@ Public Sub ImportAllSource()
obj_type_num = Val(obj_type_split(1))
obj_path = source_path & obj_type_label & "\"
FileName = Dir(obj_path & "*.bas")
- If Len(FileName) > 0 Then: Debug.Print "Importing " & obj_type_label & "..."
- Do Until Len(FileName) = 0
- obj_name = Mid(FileName, 1, InStrRev(FileName, ".") - 1)
- If obj_name <> "AppCodeImportExport" Then
- If obj_type_label = "modules" Then
- ucs2 = False
- Else
- ucs2 = UsingUcs2()
+ If Len(FileName) > 0 Then
+ Debug.Print "Importing " & obj_type_label; Tab(20);
+ obj_count = 0
+ Do Until Len(FileName) = 0
+ obj_name = Mid(FileName, 1, InStrRev(FileName, ".") - 1)
+ If obj_name <> "AppCodeImportExport" Then
+ If obj_type_label = "modules" Then
+ ucs2 = False
+ Else
+ ucs2 = UsingUcs2()
+ End If
+ ImportObject obj_type_num, obj_name, obj_path & FileName, ucs2
+ obj_count = obj_count + 1
End If
- ImportObject obj_type_num, obj_name, obj_path & FileName, ucs2
- End If
- FileName = Dir()
- Loop
+ FileName = Dir()
+ Loop
+ Debug.Print "[" & obj_count & "]"
+ End If
Next
DelIfExist TempFile()
View
@@ -8,7 +8,9 @@ matonb:
* Added Skipping for GUID & Namemap in aggressive sanitize mode.
* If AggressiveSanitize is on, also sanitize query exports.
* Append [Number] of objects exported to information lines in immediate window.
+* Append [Number] of objects imported to information lines in immediate window.
* Updated readme (removed references to terminal window).
+* Close all open forms and reports when importing (MS reserved error).
version 0.2 - 4 Apr 2013
------------------------

0 comments on commit aa3a488

Please sign in to comment.