Nested SUBs?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to convert (and recompile) a 2000 database. In the form, I have
something like:

-------------------------
Private Sub SUB1
Private Sub SUB2
....
....
....
End Sub
End Sub
-------------------------

As I'm sure you can imagine, Access is barfing on attempted compilation. WTH
is going on here? Any insight would be most appreciated.

Thanks!
 
Dennis said:
I'm trying to convert (and recompile) a 2000 database. In the form, I
have something like:

-------------------------
Private Sub SUB1
Private Sub SUB2
...
...
...
End Sub
End Sub
-------------------------

As I'm sure you can imagine, Access is barfing on attempted
compilation. WTH is going on here? Any insight would be most
appreciated.

Thanks!

Code like that could never have worked, but you're only now discovering
it because the conversion involves recompiling. You'll have to sort out
what the correct code should have been, with the two procedures not
nested, and fix it. Or else conclude that the object containing that
code is not used, because one would expect some sort of error if you
tried to run any code in it, given that the module is uncompilable.
 
You can't nest subs this way! Do this:
Private Sub SUB1
Call SUB2

End Sub

Public Sub Sub2

End Sub
 
Yeah, I know that. But that's the way it's currently coded. Needless to say,
it doesn't compile....
 
Did you notice I provided what the code should be????

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
(e-mail address removed)
www.pcdatasheet.com
 
Well, Pascal / Delphi always did allow sub, and function nesting, and it is
wonderful feature that I miss!!

When you nest functions (in a language that lets you do this), then those
functions are LOCAL to the particular sub!

For ms-access, to group functions and subs this way, you have to put them
all in a similar module, and use public/private. With Pascal, the fact of
declaring subs/functions works exactly on a conceptual level the same way
that global/local vars work in ms-access. If you needed a function to ONLY
be fore use with the current sub, then you declare the function *inside* of
the sub..and it is instantly local!

A good many languages did support this feature...and I often miss it....
 
Albert D. Kallal said:
Well, Pascal / Delphi always did allow sub, and function nesting, and
it is wonderful feature that I miss!!

When you nest functions (in a language that lets you do this), then
those functions are LOCAL to the particular sub!

For ms-access, to group functions and subs this way, you have to put
them all in a similar module, and use public/private. With Pascal,
the fact of declaring subs/functions works exactly on a conceptual
level the same way that global/local vars work in ms-access. If you
needed a function to ONLY be fore use with the current sub, then you
declare the function *inside* of the sub..and it is instantly local!

A good many languages did support this feature...and I often miss
it....

Sure, I've programmed in many such languages. Unfortunately for Dennis,
VBA isn't one of them. <g>

Working in Access VBA, I have occasionally ended up with nested Subs
like that, when I accidentally pasted code in the wrong place. I think
it's more likely that a mistake of that sort happened here, rather than
it being the result of a programmer who thought he was working in a
different language.
 
Yes (thanks). The moment I saw that bizarre structure I knew it couldn't
work. I was just wondering if anyone else had seen a case where something
similar DID work (I would've been shocked and amazed). I just wanted to cover
all the bases.

Thanks again!
 
Back
Top