joyfullservice / msaccess-vcs-addin

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

VCS 4.0.34: Unhandled error in clsDbVbeReference.GetDictionary line 162 #495

Open HughWarrington opened 4 months ago

HughWarrington commented 4 months ago

This was while doing my first full export. Right after these initial log messages:

-------------------------------------
my_database.mdb
VCS Version 4.0.34
Performing Full Export
14/03/2024 17:19:00
-------------------------------------

it said ERROR: Unhandled error found before 'On Error' directive (from memory). I then reran with debugging enabled and got this:

image

OS Name: Microsoft Windows 10 Pro (10.0.19045 Build 19045) 64-bit VCS version: 4.0.34 Office version: Microsoft® Access® for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20124) 64-bit

I'm new to Access/VBA but can supply more details if needed.

HughWarrington commented 4 months ago

Can I also just take a moment to praise the maintainers @joyfullservice and I'm sure countless others who have contributed to this project over the years. I'm a newcomer to Access/VBA and I'm taking over the maintenance of a large and ancient project. I can't say how relieved I was to find this kind of tool exists, since the 'version control' on the project I have inherited has nearly 1000 different .mdb files of different ages. Hopefully I will be able to delve into the history in a more meaningful way using this tool plus git and the tools I am familiar with.

josef-poetzl commented 4 months ago

Is it possible that a reference is broken (missing reference)? Then ref.Name cannot be executed. Try ? ref.IsBroken in immediate window if the code execution was stopped in the error line shown above.

HughWarrington commented 4 months ago

Ah yes I think that is likely. I have had many problems with missing references in this file.

joyfullservice commented 4 months ago

@HughWarrington - Thank you for the kind words! That is exactly the kind of scenario where I find this tool so helpful. You can go through each of those mdbs and export the source files, then use WinMerge or other tools to compare the differences between the versions.

Another quick tip on the VBA development side, if you haven't already done so, is to set a couple options in your VBA IDE.

image

image

These tweaks greatly improve the development experience in VBA. (Note that depending on the style of the original developers in your project, requiring variable declaration may be a phased approach if they were not in the habit of declaring them in the VBA code.)

HughWarrington commented 4 months ago

That's great, thanks for the tips!

I suppose a good improvement here might be to print a warning message 'You have a missing reference' or maybe just to silently ignore it -- if I'm honest I don't know yet what this GetDictionary code is trying to do. Perhaps I will have time to contribute a fix myself in due course.

joyfullservice commented 3 months ago

I have added some additional error handling around broken references. A broken reference does not necessarily mean the export will fail, but it is good to warn the user in case they are not already aware of it. In my testing, a broken reference does not always generate an error either, so I added handling for both cases just to make sure it gets visibility.

josef-poetzl commented 3 months ago

ref.Name will fail if broken ref from a type lib. =>

If ref.IsBroken Then
   If ref.Kind = vbext_rk_Project Then
      Log.Error eelWarning, "Broken reference for " & ref.Name & " (" & ref.FullPath & "). " & _
                        "This may cause errors in the export process.", ModuleName(Me) & ".GetDictionary"
   Else 'vbext_rk_TypeLib
      ' only guid can be read
      Log.Error eelWarning, "Broken reference for " & ref.Guid & ". " & _
                        "This may cause errors in the export process.", ModuleName(Me) & ".GetDictionary"
   End If
End If

Code can also be designed a little more beautifully, I just wanted to show a possible solution. ;)

joyfullservice commented 3 months ago

ref.Name will fail if broken ref from a type lib. =>

Thanks for the suggestion! I have refactored the code to avoid referencing the .Name property on a broken type lib. I didn't have an easy way to test this, but it looks like it should work... 😄

josef-poetzl commented 3 months ago

strName = IIf(ref.Type = vbext_rk_Project, ref.Name, ref.Guid) Will not work because iif is a function in VBA. =>

if ref.Type = vbext_rk_Project
    strName = ref.Name
else
    strName = ref.Guid
end if

Test with tlb is simple:

  1. Insert a reference to an unregistered tlb file.
  2. close accdb
  3. delete tlb file
  4. => missing reference
joyfullservice commented 3 months ago

Good point... I forgot about the fact that VBA will evaluate all the expressions in a function. I will adjust that. 🤦

hecon5 commented 3 weeks ago

If this is working, can you close it @HughWarrington ? Thank you!

HughWarrington commented 3 weeks ago

I'm not sure how to test this without a new release?