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

The link between the forms and the querys is broken #436

Closed sotalvaro closed 7 months ago

sotalvaro commented 1 year ago

Hi Adam, I have an issue with my code when I build from file the link between the forms and the querys that load the information in there is producing me this issue:

image

Did you have any idea about that?

bclothier commented 1 year ago

If this is an Access.AccessField --- a field without a control on the form, then I recommend that you discontinue the practice of referencing it in your VBA code. An AccessField has only one member, Value but it is ephemeral and will be changed whenever the recordsource changes and that can make it hard to validate the VBA codebase.

I recommend that you instead create a hidden control on the form and reference it via a control. I normally color my hidden control red background and yellow font so that it pops out when in design view and that avoids the error.

BTW, that isn't something specific to the add-in but rather the nature of referencing an ephemeral object because it depends on having the recordsource and that it can be resolved in order to build a field list and consequently the AccessField objects, but frankly it's too bobbly-wobbly for my liking, hence the recommendation of using a hidden control instead of referencing a field directly.

hecon5 commented 1 year ago

I will also say @bclothier is right (use hidden controls) and add some additional thoughts...I cannot count the number of times I've discovered my code isn't compiling only to discover that the field in the RecordSource is named the same as a control, and someone changed the Recordsource object name to something else and now things are borked. Therefore, we've spent a TON of time going through and ensuring all controls have "Box" or "Combo" or something to clearly indicate that you're talking about a control and not a field, and managing all linking through the Control object and trying our dangdest to never directly reference recordsource fields.

joyfullservice commented 1 year ago

@bclothier - Thanks for your insight on this! Ironically my coworker ran into this very issue today with a project we were building from source. Sure enough, the code in a report event was referencing a field name directly. I... may or may not have been the one that wrote that code a number of years ago.... 🤦‍♂️ Great tips from you and @hecon5 as well! Thanks for sharing.

hecon5 commented 10 months ago

With this answer, is this complete?

hecon5 commented 7 months ago

Bump; can this be closed?