01-22-2019
07:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
01-22-2019
07:30 AM
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.