Basic Question

  • Thread starter Thread starter Sash
  • Start date Start date
S

Sash

I'm getting an error message "Procedure too large".

I created a form with three sets of buttons contained in a frame so that I
can say if the frame value is the button value process the file differently.
In creating the code, I right clicked the frame and created an event
procedure which reads "Private Sub Frame50_AfterUpdate" or something similar
for the other two frames.

Are each of these considered a separate procedure even thought when I right
click to update the code is all together? I'm just trying to figure out how
to get past the too large problem.
 
And are comments part of what Access is counting? Because I have a lot of
comments in this procedure.
 
Never seen that myself, but just how many comments do you have? Tip: If you
have more lines of comments than actual lines of code, you should edit them.

Export the module with the offending procedure to save the comments, then
delete out the comments and try again.
 
A VBA procedure does have a maximum size. I can't recall the limit right now.

If you have a procedure (Sub or Function) that is too large, then see if you
can break the procedure into sections to be called as needed. Often doing so
will improve the readability (for the human) of the code.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
Why? You should have as many comments as it takes to explain what you're
doing.
 
Thanks John. I just posted a question about calling a procedure. If I can
get it to work, it will greatly improve the funcationality and readability!!
 
But wouldn't you agree that if there are 10-15 lines of comments per single
line of code that's obvious in what it does that its probably to many as in...

'Create an object variable pointing back to the current workspace of the
engine,
'we'll use this later to work with the various tables to insert and edit
records as
'we 'loop through them via the recordSet object, while we'll be using DAO to
directly
'add and edit records using the recordSet object and .Edit, .Update, the
..Execute
'method of the database object will be used to insert the new records, this
will
'allow us to encapsulate the insert in an explicit transaction
'using .BeginTrans, .CommitTrans and .Rollback so that if one part of the
insert
'fails we can trap the errors and allow or disallow the change

Set db = DBEngine(0)(0)

Most of the comments above could be edited down as the remaining lines of
code would infer what we're doing. Imagine though a new programmer leaving
that amount of comments for nearly every single line of code - that's the
direction that I was going in. If its an educational setting, I could see
extensive comments, but in a real-world application, I can only see a handful
of comments (one or two lines) per line of code to briefly elaborate on why
we're doing what we're doing, unless its something utterly commplicated that
needs to be explained, and then most likely at the top of the SUB/FUNCTION.
As one of my old instructors used to say - why use 5 words, when 5,000 will
do.
 
I'm not sure I agree with you.

For one thing, in many situations the developer won't necessarily be the one
who maintains the application. And even if the same person is doing
maintenance, if it's several years since the application was written, it may
well be a lifesaver to have those verbose comments there.
 
And darn if my post didn't post...

I was referring to situations were a developer goes hog-wide and states the
obvious in comments when the line of code speaks for itself. As in...

'Declare variables
Dim a as Integer

'set a = 1
a = 1

The code here is pretty obvious as to what's it doing hence the comments are
redundant. Now if you had something unexpected...

'Display the 'Trailers' page on the tabcontrol by the PageIndex value, this
will allow
'additional pages to be added to the tabcontrol without having to modify the
code
'the alternative would be [Forms]![frmManifest]![tbCtrl] = 1 which would break
'if the page order is changed or addl pages added
[Forms]![frmManifest]![tbCtrl] =
[Forms]![frmManifest]![tbCtrl].PageIndex("pgTrailers")

Or comments that elaborate on why a block of code exists to summarize whats
happening such as
'Loop the records in the table checking to see if related records existing
in the
'journal entries table and if they do confirm that the amounts being charged
to each
'account equal the actual amount refunded to the guest. If a record doesn't
exist,
'create a single record billing the refund back to the generic account for
the department invovled.
 
Back
Top