> This sub worked fine several times then suddenly stopped working. Can
> anyone help me figure out what is wrong?
[quoted text clipped - 59 lines]
> --
> Rhino
See remarks interspersed below....
> The problem is that your if statement is checking, not whether the value
> exists, but whether the value is equal to FALSE. This throws an error if
> the value is not defined at all.
As Homer Simpson would say, "D'oh!". Yeah, I should have seen that. I found
a similar fragment in a Google newsgroup search and didn't think through the
difference between what problem the post was handling and what I was doing.
I thought it was the way VBA tests for existence of a field but now I see
that it isn't.
> Simpler is to retrieve the value and trap the error if not defined ...
>
[quoted text clipped - 9 lines]
> end if
> Msgbox Msg
Thanks for the suggestion!
> Separately, there's no point putting the 'Dim revisionDate' statement
> within the If clause. 'Dim' is a compiler directive, not a runtime
> instruction, so the variable is always declared anyway.
Sure, but isn't it always better to declare the variable to be a specific
type rather than let it default to variant? That's really the only reason
I'm doing it.
--
Rhino
>> This sub worked fine several times then suddenly stopped working. Can
>> anyone help me figure out what is wrong?
[quoted text clipped - 60 lines]
>> --
>> Rhino
Jezebel - 03 Feb 2006 07:05 GMT
> Sure, but isn't it always better to declare the variable to be a specific
> type rather than let it default to variant? That's really the only reason
> I'm doing it.
Absolutely. I was just being lazy. My point is that the declarations should
all be at the top of the function, not interspersed with other code.
Rhino - 03 Feb 2006 15:13 GMT
Ahh, okay, thanks for clearing that up :-)
Just for interest sake, why should the declarations always be at the top of
the function? Is there any real functional benefit? In Java, my main
language these days, it's really just a style thing: some programmers feel
that declarations ought to be at the top where they are more visible, others
prefer to do declarations just before the variable is needed but both
approaches work just fine.
By the way, I've got my CustomProperty-related subs working just fine thanks
to your suggestion. Thanks for your help with this (and other questions)!
--
Rhino
>> Sure, but isn't it always better to declare the variable to be a specific
>> type rather than let it default to variant? That's really the only reason
[quoted text clipped - 3 lines]
> should all be at the top of the function, not interspersed with other
> code.
Jezebel - 03 Feb 2006 21:45 GMT
Coding styles and conventions are methods that programmers have found,
through experience, to reduce the opportunities for bugs and to improve
maintainability. Declaring your variables is one (try writing a large app
without using 'option explicit'!); declaring them all before any code is
another.
There is one functional issue: remove the option explicit from your module,
and insert another reference to the variable *before* the declaration (which
is the sort of thing that happens when code gets modified by someone
else) -- the code runs OK if the IF condition is not met, and throws a
'duplicate declaration' error if it is.
> Ahh, okay, thanks for clearing that up :-)
>
[quoted text clipped - 19 lines]
>> should all be at the top of the function, not interspersed with other
>> code.