Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
DRoam
in reply to: andrew_canfield

Variables declared within block statements like If/Then, Try/Catch, For/Next, etc. have "block scope" and are only available within the code block in which they're declared. So if you try to use them outside the block, you'll get a compile error.

 

To make the variable available to your entire procedure, declare it outside the Try/Catch block, and then just set its value within the Catch block, like this:

 

Dim oVariable As VariableType
Try
     '...
Catch
     oVariable = ...
End Try

I'm surprised this worked at all in your local rule. It's difficult to determine why without seeing more of your code. But regardless, you should only declare a variable within a block if it's ONLY going to be used in that block.