Compile Error

L

LMB

Hi,

Using Access 2000 and I guess it's time to really try to understand VB. I
do have the book Beginning VB for Access 2000 but the thickness of the book
intimidates me and forces me to just leave it on the shelf. Well, I think I
have learned all I can by trial and error and clicking around to see what
happens and I don't know the vb terms well enough to search for excatly what
my problem is. I will be picking it up pretty soon but before I do, I was
wondering what the error message below is telling me? This code was created
by the program when I used the wizard to make a command button on a form to
open a report. The button works but after someone told me that I should
debug compile and save anytime I insert code (maybe they meant when I made
it myself instead of using a wizard?) I decided to look at the properties
of all my buttons and do this. When I clicked on debug/compile, I got this
message.........Thanks Linda

Compile error: Label not defined.

The curser jumps to the following line...
On Error GoTo Err_btnDepartmentSeniority_Click

This is the whole subroutine...Is this a subroutine or a module or what?
___________________________________________________________
Private Sub btnDepartmentSeniority_Click()
On Error GoTo Err_btnDepartmentSeniority_Click

Dim stDocName As String

stDocName = "rptDepartmentSeniority"
DoCmd.OpenReport stDocName, acPreview

Exit_btnDepartmentVTO_Click:
Exit Sub

Err_btnDepartmentVTO_Click:
MsgBox Err.Description
Resume Exit_btnDepartmentVTO_Click

End Sub
_____________________________________________________________
 
D

Duane Hookom

If you have a line that might send code execution to another line, you need
to have that other line defined. Try:

Private Sub btnDepartmentSeniority_Click()
On Error GoTo Err_btnDepartmentSeniority_Click

Dim stDocName As String

stDocName = "rptDepartmentSeniority"
DoCmd.OpenReport stDocName, acPreview

Exit_btnDepartmentVTO_Click:
Exit Sub

Err_btnDepartmentSeniority_Click:
MsgBox Err.Description
Resume Exit_btnDepartmentVTO_Click

End Sub
 
T

tina

well, you really should compile your code, whether it's all written by
wizards, or hand-written, or a mixture of both. if there's an error in the
code, it's not going to go away just because you don't know it's there
(don't we wish...! ;) )

in the case of this particular error, the system is telling you that the
"label" - Err_btnDepartmentSeniority_Click - doesn't exist in the procedure
(or subroutine; AFAIK either term is okay). and when you read through the
whole procedure, you see that indeed it is not there. instead, the "label"
for the error-handling code is Err_btnDepartmentVTO_Click.

so change your code to

Private Sub btnDepartmentSeniority_Click()
On Error GoTo Err_btnDepartmentSeniority_Click

Dim stDocName As String

stDocName = "rptDepartmentSeniority"
DoCmd.OpenReport stDocName, acPreview

Exit_btnDepartmentSeniority_Click:
Exit Sub

Err_btnDepartmentSeniority_Click:
MsgBox Err.Description
Resume Exit_btnDepartmentSeniority_Click

End Sub

compare each line of the above code with your original code, so you can see
exactly what changes i made, and where. there's a consistent pattern there
that should be easy to pick up on.

btw, don't feel bad about being intimidated by VBA - you're not alone. when
i took a VBA class after using Access macros exclusively for two years, i
thought i was going to have a heart attack from the stress - i had a
TERRIBLE time trying to understand the basics. but i just forced myself to
quit using macros (cold turkey) and do everything in VBA, and gradually it
began to make sense and got easier. trust me - once you get the hang of VBA,
you'll love all the things you can accomplish with it, stuff you could never
dream of doing with macros! so hang in there! :)

hth
 
L

LMB

Thanks, worked great! Now I need to fix a few more. I guess this is a good
example of what happens when a person copies an object and doesn't quite
change all the properties? I think that is what must have happened. Or
maybe I copied a button, but I don't think I would have done that because I
know I would have had to change the code behind it, but it does say btnVTO
not rptVTO....I'll try to figure it out. I learn/remember best when I have
made a mistake!

Linda
 
L

LMB

Thanks, Tina

OK, I will compile my code from now on. I used the word subroutine because
I remember on an episode in Star Trek, Commander Data had created a
subroutine and explained it as a "Program within a program", when I saw the
word Sub, I just kinda figured it was that. Procedure is what I think I
have read before somewhere.

I can handle the compile part when it doesn't have a problem. Thanks for
the moral support about VBA, I in fact have an appointment to see an
academic advisor this Friday to look into what I need to do to get an
individualized degree in healthcare and software design or something like
that. After getting my transcripts from 20 years ago, they may just say,
forget it! <g>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top