Skip to content

Commit 03b8e74

Browse files
Support import of non-compiling code modules
Reworked the module import to be able to import code that has compile issues, while still saving the code modules. This ended up being more difficult than I expected, but seems to work well now. #236
1 parent babb9e3 commit 03b8e74

File tree

6 files changed

+50
-12
lines changed

6 files changed

+50
-12
lines changed

Testing/Testing.accdb.src/modules/Module1.bas

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Private Type DEVNAMES
3838
extra(1 To 255) As Byte
3939
End Type
4040

41-
41+
'noncompilingcodeissue ' Showing that we can build even with VBA errors
4242

4343
Public Sub PrtMipCols(ByVal strName As String)
4444

Testing/Testing.accdb.src/vcs-options.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"Info": {
3-
"AddinVersion": "3.4.10",
3+
"AddinVersion": "3.4.13",
44
"AccessVersion": "14.0 32-bit"
55
},
66
"Options": {

Version Control.accda.src/dbs-properties.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"Type": 10
4242
},
4343
"AppVersion": {
44-
"Value": "3.4.12",
44+
"Value": "3.4.13",
4545
"Type": 10
4646
},
4747
"Auto Compact": {

Version Control.accda.src/modules/modImportExport.bas

+1-8
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ Public Sub Build(strSourceFolder As String, blnFullBuild As Boolean)
192192
Dim colFiles As Collection
193193
Dim varFile As Variant
194194
Dim strType As String
195-
Dim blnCompiled As Boolean
196195

197196
Dim strText As String ' Remove later
198197

@@ -374,16 +373,10 @@ Public Sub Build(strSourceFolder As String, blnFullBuild As Boolean)
374373

375374
' After importing modules, we need to save them before adding
376375
' other properties like descriptions or hidden attributes
377-
If cCategory.ComponentType = edbModule Then
378-
CompileAndSaveAllModules
379-
blnCompiled = True
380-
End If
376+
If cCategory.ComponentType = edbModule Then SaveAllModules
381377
End If
382378
Next cCategory
383379

384-
' Ensure that we have compiled and saved all VBE modules
385-
If Not blnCompiled Then CompileAndSaveAllModules
386-
387380
' Initialize forms to ensure that the colors/themes are rendered properly
388381
' (This must be done after all objects are imported, since subforms/subreports
389382
' may be involved, and must already exist in the database.)

Version Control.accda.src/modules/modVCSUtility.bas

+45
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Option Compare Database
1010
Option Private Module
1111
Option Explicit
1212

13+
Private Const ModuleName = "modVCSUtility"
14+
1315

1416
'---------------------------------------------------------------------------------------
1517
' Procedure : GetAllContainers
@@ -577,3 +579,46 @@ Public Sub CompileAndSaveAllModules()
577579
DoEvents
578580
Perf.OperationEnd
579581
End Sub
582+
583+
584+
'---------------------------------------------------------------------------------------
585+
' Procedure : SaveAllModules
586+
' Author : Adam Waller
587+
' Date : 7/14/2021
588+
' Purpose : Loop through the VBE modules and classes, saving each one in Access.
589+
'---------------------------------------------------------------------------------------
590+
'
591+
Public Sub SaveAllModules()
592+
593+
Dim proj As VBProject
594+
Dim cmp As VBComponent
595+
Dim colNames As Collection
596+
Dim varMod As Variant
597+
598+
If DebugMode(True) Then On Error GoTo 0 Else On Error Resume Next
599+
600+
Set proj = GetVBProjectForCurrentDB
601+
Set colNames = New Collection
602+
603+
' Loop through and collect list of names.
604+
' (We can't save here, or we will get an error)
605+
For Each cmp In proj.VBComponents
606+
Select Case cmp.Type
607+
Case vbext_ct_ClassModule, vbext_ct_StdModule
608+
If (cmp.Saved = False) Then colNames.Add cmp.Name
609+
End Select
610+
Next cmp
611+
612+
' Set the active project to the CODE (add-in) project BEFORE
613+
' attempting to save the modules. Otherwise we will hit errors.
614+
Set VBE.ActiveVBProject = GetCodeVBProject
615+
616+
' Save each item in the list
617+
For Each varMod In colNames
618+
On Error GoTo 0
619+
DoCmd.Save acModule, varMod
620+
Next varMod
621+
622+
CatchAny eelError, "Error saving VBA modules", ModuleName & ".SaveAllModules"
623+
624+
End Sub

Version Control.accda.src/vcs-options.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"Info": {
3-
"AddinVersion": "3.4.11",
3+
"AddinVersion": "3.4.13",
44
"AccessVersion": "14.0 32-bit"
55
},
66
"Options": {

0 commit comments

Comments
 (0)