joyfullservice / msaccess-vcs-addin

Synchronize your Access Forms, Macros, Modules, Queries, Reports, and more with a version control system.
Other
203 stars 40 forks source link

Incorrect theme in built version #48

Closed cenx1 closed 4 years ago

cenx1 commented 4 years ago

Systeminfo

Access Version: MS Office 365 64bit

msaccess-vcs-integration: 3.1.14

Details

If I select a theme for a database, say Integral, and export and build the database, the active theme is incorrect.

Steps to reproduce:

  1. Open the Testing database in this project.
  2. Open frmMain in Design Mode and select a theme, e.g. Integral and save.
  3. Export the database and build from source afterwards.
  4. Close the database and open it again.
  5. Open frmMain
    • Expected: The form uses the Integral theme
    • Actual: The form uses the Organic theme or some other theme.

Observations

I will add more info as I come upon it.

joyfullservice commented 4 years ago

Thanks for your work on this! The class for the theme will probably be very similar to the one for shared images (clsDbSharedImage). I was envisioning exporting the themes into a "themes" folder as unzipped contents with each parent folder representing a theme. At build time, the contents would be zipped and loaded into the MSysResources table.

cenx1 commented 4 years ago

It sounds like you have a good understanding of how it works and you thoughts seem valid. I hope we can figure this out as it gives me a lot of extra work to look all the files through everytime I do an export before comitting.

But I am a little worried that changes made to the MSysResources table are overridden after database is restarted. I tried with making a procedure in the project that I am exporting and added it to run after build, but it was like the changes to MSysResources did not take effect when the database was restarted.

joyfullservice commented 4 years ago

What happens if you load the theme and database properties before importing the forms and reports?

joyfullservice commented 4 years ago

Made some good progress this morning on theme support... I am now able to extract the themes from the source database and save them in unzipped format. 3f15102 Of course the real test will be what happens when we import them back into the database, but I am optimistic that we will find a way to do this.

cenx1 commented 4 years ago

Nice job!

What I have done until now was to create two functions, one for saving theme and one for loading:

Public Function SetTheme()

    Dim rsMsysResources As DAO.Recordset2
    Dim rsAttachment As DAO.Recordset2
    Dim strThemePath As String
    strThemePath = CurrentProject.Path & "\CustomTheme.thmx"

    Set rsMsysResources = CurrentDb.OpenRecordset("SELECT * FROM MSysResources WHERE [Type] = 'thmx'", dbOpenDynaset)
    If Not rsMsysResources.EOF Then rsMsysResources.MoveLast

    If Not rsMsysResources.EOF Then

        Debug.Print "Update " & rsMsysResources("Name")
        rsMsysResources.Edit
        Set rsAttachment = rsMsysResources("Data").Value
        If Not rsAttachment.EOF Then rsAttachment.Delete

    Else

        Debug.Print "Add new theme (CustomTheme)"
        rsMsysResources.AddNew
        rsMsysResources("Extension") = "thmx"
        rsMsysResources("Type") = "thmx"
        Set rsAttachment = rsMsysResources("Data").Value

    End If

    rsMsysResources("Name") = "CustomTheme"

    rsAttachment.AddNew
    Debug.Print "Load theme attachment from file '" & strThemePath & "'"
    rsAttachment("FileData").LoadFromFile strThemePath
    rsAttachment.Update
    rsMsysResources.Update

    rsMsysResources.Close

    Dim p As Property
    Dim strPropName
    Dim blnPropFound As Boolean
    blnPropFound = False
    strPropName = "Theme Resource Name"
    For Each p In CurrentDb.Properties
        If p.Name = strPropName Then
            Debug.Print "Theme Resource Name exists - update with 'CustomTheme'"
            CurrentDb.Properties("Theme Resource Name") = "CustomTheme"
            blnPropFound = True
        End If
    Next

    If Not blnPropFound Then
        Debug.Print strPropName & " was not found - create new property with value 'CustomTheme'"
        Set p = CurrentDb.CreateProperty(strPropName, dbText, "CustomTheme")
        CurrentDb.Properties.Append p
    End If

    Debug.Print "Done"

End Function

and

Public Function SaveTheme()

    Dim rsAttachment As DAO.Recordset2
    Dim rsMsysResources As DAO.Recordset2
    Dim strThemePath  As String
    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    strThemePath = CurrentProject.Path & "\CustomTheme.thmx"
    Set rsMsysResources = CurrentDb.OpenRecordset("SELECT * FROM MSysResources WHERE [Type] = 'thmx'", dbOpenDynaset)
    If Not rsMsysResources.EOF Then rsMsysResources.MoveLast
    Set rsAttachment = rsMsysResources("Data").Value
    If fso.FileExists(strThemePath) Then fso.DeleteFile strThemePath
    Debug.Print "Save theme attachment to '" & strThemePath; "'"
    rsAttachment("FileData").SaveToFile strThemePath
    rsAttachment.Close
End Function

The two functions were invoked after export (SaveTheme) and after build (SetTheme).

Maybe you can use some of the code in there (I know it is rough). 😄

It have been acting pretty consistent since I implemented these.

cenx1 commented 4 years ago

I will take a look at what you have come up with so far. 👍

joyfullservice commented 4 years ago

Thanks, @cenx1! That is a helpful jump start on the import side.

joyfullservice commented 4 years ago

Success!! 👍 I was able to get the theme to load into the database during build! I need to polish up a few things on the coding side, but I wanted to pass on the good news. 😄 The key was I needed to import the theme before importing the objects that depend on the theme.

When the first form or report is created/imported into the database, this automatically creates the MSysResources table. Since you have to have the theme before you import the form, but you can't import the theme till you have a resources table, I am creating a temporary form to force the generation of the table, then loading the themes, then proceeding to load the rest of the objects and database properties. In my proof of concept, this successfully loaded and applied the theme to my form.

joyfullservice commented 4 years ago

@cenx1 - Could you do some testing after the latest update dc8e38c? It seems to be working for me to export and import themes. Then if you have time, it would be great if we could finish this out with a few finishing touches and enhancements:

Thanks for your help with this project! Hopefully my work on the theme functionality will help save you time on your end as well. 😄

cenx1 commented 4 years ago

Nice job! 👍 I tested the latest update and can confirm that the theme is exported with the project and added upon build time.

I do however get two themes after build. I believe the unwanted theme that was not exported is added automatically somehow during build. If I do a compact and repair the unwanted theme is removed and only the desired theme is present.

Maybe the unwated theme is some kind of default for when creating the first form in a project?

joyfullservice commented 4 years ago

That's good to know about the unused themes being removed in a compact and repair.

Yes, I believe you are correct about the default theme being added when that first temporary form is created to trigger Access to add the MSysResources table.

The default theme is specified in the application options:

2020-06-04 06_51_40-Microsoft Access

Probably a simple approach here would be to delete any records in the MSysResources table immediately after it is created. Themes would then be loaded from the source files as part of the build, and you wouldn't need to worry about having themes that were not part of the export.

cenx1 commented 4 years ago

Thanks for the information. For some reason I had the Organic specified in the Default Theme section you just showed.

joyfullservice commented 4 years ago

Thanks again, Casper, for your work on #50 I believe that fully resolves this issue, but feel free to reopen it if there are further issues with themes.