From d144f5a22649be6e626beee0846e28cb7d05ea6d Mon Sep 17 00:00:00 2001 From: joyfullservice Date: Tue, 20 Jul 2021 16:39:35 -0500 Subject: [PATCH] Resolve module import issue I am now able to successfully build the test database and the add-in from source. Fixes #236 --- Version Control.accda.src/dbs-properties.json | 2 +- .../modules/clsDbModule.cls | 82 ++++--------------- .../modules/modImportExport.bas | 4 - .../modules/modVCSUtility.bas | 42 ---------- Version Control.accda.src/vbe-project.json | 2 +- Version Control.accda.src/vcs-options.json | 2 +- 6 files changed, 18 insertions(+), 116 deletions(-) diff --git a/Version Control.accda.src/dbs-properties.json b/Version Control.accda.src/dbs-properties.json index 724eea96..aac4f2ea 100644 --- a/Version Control.accda.src/dbs-properties.json +++ b/Version Control.accda.src/dbs-properties.json @@ -41,7 +41,7 @@ "Type": 10 }, "AppVersion": { - "Value": "3.4.14", + "Value": "3.4.15", "Type": 10 }, "Auto Compact": { diff --git a/Version Control.accda.src/modules/clsDbModule.cls b/Version Control.accda.src/modules/clsDbModule.cls index 7817de07..00355c8c 100644 --- a/Version Control.accda.src/modules/clsDbModule.cls +++ b/Version Control.accda.src/modules/clsDbModule.cls @@ -19,7 +19,7 @@ Option Explicit Private Const ModuleName As String = "clsDbModule" -Private m_Module As VBComponent +Private m_Module As AccessObject Private m_AllItems As Collection Private m_blnModifiedOnly As Boolean @@ -85,18 +85,22 @@ Private Sub IDbComponent_Import(strFile As String) strName = GetObjectNameFromFileName(strFile) udtFile = ParseSourceFile(strFile, strName) - ' Check to see if we have an Access object with this name - If Not ModuleExists(strName) Then ImportModuleStub strName, udtFile.blnIsClass - ' Write to a new file using system encoding (converting from UTF-8) strTempFile = GetTempFile WriteFile udtFile.strContent, strTempFile, GetSystemEncoding - ' Import the source file to the code module + ' Import the source code LoadVbeModuleFromFile strTempFile, strName + ' Make sure the correct project is active before saving. + Set VBE.ActiveVBProject = GetVBProjectForCurrentDB + DoCmd.Save acModule, strName + + ' Set reference to object + Set m_Module = CurrentProject.AllModules(strName) + ' Save hash, update the index, and remove the temp file - VCSIndex.Update Me, eatImport, GetCodeModuleHash(IDbComponent_ComponentType, m_Module.Name) + VCSIndex.Update Me, eatImport, GetCodeModuleHash(IDbComponent_ComponentType, strName) DeleteFile strTempFile End Sub @@ -204,70 +208,15 @@ Private Sub LoadVbeModuleFromFile(strFile As String, strName As String) If DebugMode(False) Then On Error GoTo 0 Else On Error Resume Next ' Load from the file - Set m_Module = .Import(strFile) + .Import strFile End With Perf.OperationEnd - + CatchAny eelError, "Error importing VBA code for " & strName, ModuleName & ".LoadVbeModuleFromFile" End Sub -'--------------------------------------------------------------------------------------- -' Procedure : ImportModuleStub -' Author : Adam Waller -' Date : 7/12/2021 -' Purpose : Import a blank code module as text so it can be loaded into Access before -' : overlaying the content through VBE. (This allows us to use DoCmd.Save to -' : save the code changes, which is not available when a new module is created -' : through a VBE import. -'--------------------------------------------------------------------------------------- -' -Private Sub ImportModuleStub(strName As String, blnAsClass As Boolean) - - Dim cContent As clsConcat - Dim strTempFile As String - - Set cContent = New clsConcat - - ' Save the template content as a file - strTempFile = GetTempFile - With New clsConcat - .AppendOnAdd = vbCrLf - If blnAsClass Then - .Add "Attribute VB_GlobalNameSpace = False" - .Add "Attribute VB_Creatable = False" - .Add "Attribute VB_PredeclaredId = False" - .Add "Attribute VB_Exposed = False" - End If - .Add "' Stub module for import by MSAccessVCS" - .Add "noncompilingcode 'issue here" - ' Load as text without BOM - WriteFile .GetStr, strTempFile, "Windows-1252" - End With - - LoadFromText acModule, strName, strTempFile - DeleteFile strTempFile - -End Sub - - -'--------------------------------------------------------------------------------------- -' Procedure : ModuleExists -' Author : Adam Waller -' Date : 7/13/2021 -' Purpose : Returns true if the module or class exists in the current database -'--------------------------------------------------------------------------------------- -' -Private Function ModuleExists(strName As String) As Boolean - Dim objTest As AccessObject - If DebugMode(True) Then On Error Resume Next Else On Error Resume Next - Set objTest = CurrentProject.AllModules(strName) - CatchAny eelNoError, vbNullString, , False - ModuleExists = Not objTest Is Nothing -End Function - - '--------------------------------------------------------------------------------------- ' Procedure : Merge ' Author : Adam Waller @@ -295,7 +244,7 @@ End Sub ' Private Sub ExportVbComponent(strFile As String) Perf.OperationStart "Export VBE Module" - m_Module.Export strFile + GetVBProjectForCurrentDB.VBComponents(m_Module.Name).Export strFile Perf.OperationEnd End Sub @@ -320,7 +269,7 @@ Private Function IDbComponent_GetAllFromDB(Optional blnModifiedOnly As Boolean = Set proj = GetVBProjectForCurrentDB For Each oMod In CurrentProject.AllModules Set cModule = New clsDbModule - Set cModule.DbObject = proj.VBComponents(oMod.Name) + Set cModule.DbObject = oMod If blnModifiedOnly Then If cModule.IsModified Then m_AllItems.Add cModule, oMod.Name Else @@ -463,7 +412,7 @@ End Property '--------------------------------------------------------------------------------------- ' Private Function GetExtension() As String - If m_Module.Type = vbext_ct_StdModule Then + If GetVBProjectForCurrentDB.VBComponents(m_Module.Name).Type = vbext_ct_StdModule Then GetExtension = ".bas" Else GetExtension = ".cls" @@ -547,4 +496,3 @@ End Property Public Property Get Parent() As IDbComponent Set Parent = Me End Property - diff --git a/Version Control.accda.src/modules/modImportExport.bas b/Version Control.accda.src/modules/modImportExport.bas index f9bff27a..6eb12000 100644 --- a/Version Control.accda.src/modules/modImportExport.bas +++ b/Version Control.accda.src/modules/modImportExport.bas @@ -370,10 +370,6 @@ Public Sub Build(strSourceFolder As String, blnFullBuild As Boolean) ' Show category wrap-up. Log.Add "[" & colFiles.Count & "]" & IIf(Options.ShowDebug, " " & LCase(cCategory.Category) & " processed.", vbNullString) Perf.ComponentEnd colFiles.Count - - ' After importing modules, we need to save them before adding - ' other properties like descriptions or hidden attributes - If cCategory.ComponentType = edbModule Then SaveAllModules End If Next cCategory diff --git a/Version Control.accda.src/modules/modVCSUtility.bas b/Version Control.accda.src/modules/modVCSUtility.bas index 97cef5aa..8b5fbe87 100644 --- a/Version Control.accda.src/modules/modVCSUtility.bas +++ b/Version Control.accda.src/modules/modVCSUtility.bas @@ -580,45 +580,3 @@ Public Sub CompileAndSaveAllModules() Perf.OperationEnd End Sub - -'--------------------------------------------------------------------------------------- -' Procedure : SaveAllModules -' Author : Adam Waller -' Date : 7/14/2021 -' Purpose : Loop through the VBE modules and classes, saving each one in Access. -'--------------------------------------------------------------------------------------- -' -Public Sub SaveAllModules() - - Dim proj As VBProject - Dim cmp As VBComponent - Dim colNames As Collection - Dim varMod As Variant - - If DebugMode(True) Then On Error GoTo 0 Else On Error Resume Next - - Set proj = GetVBProjectForCurrentDB - Set colNames = New Collection - - ' Loop through and collect list of names. - ' (We can't save here, or we will get an error) - For Each cmp In proj.VBComponents - Select Case cmp.Type - Case vbext_ct_ClassModule, vbext_ct_StdModule - If (cmp.Saved = False) Then colNames.Add cmp.Name - End Select - Next cmp - - ' Set the active project to the CODE (add-in) project BEFORE - ' attempting to save the modules. Otherwise we will hit errors. - Set VBE.ActiveVBProject = GetCodeVBProject - - ' Save each item in the list - For Each varMod In colNames - On Error GoTo 0 - DoCmd.Save acModule, varMod - Next varMod - - CatchAny eelError, "Error saving VBA modules", ModuleName & ".SaveAllModules" - -End Sub diff --git a/Version Control.accda.src/vbe-project.json b/Version Control.accda.src/vbe-project.json index 0b5edb2f..14df9ed3 100644 --- a/Version Control.accda.src/vbe-project.json +++ b/Version Control.accda.src/vbe-project.json @@ -5,7 +5,7 @@ }, "Items": { "Name": "MSAccessVCS", - "Description": "Version 3.4.5 deployed on 6/17/2021", + "Description": "Version 3.4.15 deployed on 7/20/2021", "FileName": "Version Control.accda", "HelpFile": "", "HelpContextId": 0, diff --git a/Version Control.accda.src/vcs-options.json b/Version Control.accda.src/vcs-options.json index 7f949af9..8227d225 100644 --- a/Version Control.accda.src/vcs-options.json +++ b/Version Control.accda.src/vcs-options.json @@ -1,6 +1,6 @@ { "Info": { - "AddinVersion": "3.4.14", + "AddinVersion": "3.4.15", "AccessVersion": "14.0 32-bit" }, "Options": {