Skip to content

Commit

Permalink
Resolve module import issue
Browse files Browse the repository at this point in the history
I am now able to successfully build the test database and the add-in from source. Fixes #236
  • Loading branch information
joyfullservice committed Jul 20, 2021
1 parent 4a1be96 commit d144f5a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 116 deletions.
2 changes: 1 addition & 1 deletion Version Control.accda.src/dbs-properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"Type": 10
},
"AppVersion": {
"Value": "3.4.14",
"Value": "3.4.15",
"Type": 10
},
"Auto Compact": {
Expand Down
82 changes: 15 additions & 67 deletions Version Control.accda.src/modules/clsDbModule.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -547,4 +496,3 @@ End Property
Public Property Get Parent() As IDbComponent
Set Parent = Me
End Property

4 changes: 0 additions & 4 deletions Version Control.accda.src/modules/modImportExport.bas
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
42 changes: 0 additions & 42 deletions Version Control.accda.src/modules/modVCSUtility.bas
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Version Control.accda.src/vbe-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion Version Control.accda.src/vcs-options.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Info": {
"AddinVersion": "3.4.14",
"AddinVersion": "3.4.15",
"AccessVersion": "14.0 32-bit"
},
"Options": {
Expand Down

0 comments on commit d144f5a

Please sign in to comment.