As far as memory variables, you don't need to worry about them. I would,
however, as a matter of good practice allways close any recordsets and set
thier variables to nothing. There are a couple of ways to do that, and it
will depend on the circumstances. My favorite (or favourite if you are not
US
) is to use a Boolean variable to keep unwanted code from executing. for
example:
Sub MySub()
Dim blnNoGo
blnNoGo = False 'Not necessary as Boolean is initialized as False, but
good
'practice
A bunch of Code Here
Select Case x
Case is = 1
Stuff for 1
Case is = 99
Stuff for 99
Case Else
blnNoGo = True
End Select
If blnNoGo then
rst.close
set rst = nothing
Else
a bunch more code
Endif
End Sub
Or
Sub MySub()
A bunch of Code Here
Select Case x
Case is = 1
Stuff for 1
Case is = 99
Stuff for 99
Case Else
rst.close
Set rst = nothing
Exit Sub
End Select
a bunch more code
End Sub
:
Either way, depending on your style and the requirements of the sub. Main
Rule is KEEP IT SIMPLE! ie which ever is easiest for you are another to have
to modify or debug in the future.
Now, GoTo. In every programming language, there is a GoTo statement. It is
not in of itselft evil, it is that it has been used so badly, that it is
taught never to use it. In the old days of basic when there were line
numbers, it was used a lot. What developed was called "Spagetti Code". That
is, it was almost impossible to follow the logic. There also existed the
problem of jumping outside of a current sub or function and never coming
back. This creates all kinds of problems, stack overflows, etc. The GoTo is
like a gun. Gotos don't create bad code, Programmers create bad code. The
Goto, however has been pretty universally banned.
I will, on the rare ocassion, use a Goto. But, I have my own rules on when
and how. I only use it when otherwise, the codeing in the rest of the Sub or
Function would be difficult or have a bunch of nested If's. I never go
outside the sub. I never go up, that is back toward the top of the sub,
there are all kinds of looping and for next statements for that. It is only
to get out of a sub when it is the cleanest way to do it and it is alwasy to
a tag where clean up at the end of the sub occurs.