Use TryGet pattern for transient values

A number of objects may have extra properties or something where it might not exist for all instances. A good example might be finding Controlsource property on an Access.Control variable:

Not all controls have a ControlSource property and thus can fail to run. A common approach is to use OERN:

This will work OK but this can significantly clutter the code, since we have to check whether there was an error. A more realistic example might look like this:

As you see, we’ve added a OERN block, and 2 If blocks just to handle the cases where controls might not have a ControlSource. We can do better by extracting this into a function:

Your code then become:

Which is much more readable and easier to understand. The access to the src is contained within the If TryGetControlSource(...) Then so it’s easy to understand it’s only meant to be used when it’s true.