Compile Error

Mike Hughes

Registered User.
Local time
Today, 11:11
Joined
Mar 23, 2002
Messages
493
I have a command button on a form to run several queries. When I try to run it I get a Compile error: “Duplicate declaration in current scope”

For the line “Private Sub Command27_Click()”

Would someone please tell me what I'm doing wrong? Thanks



Private Sub Command27_Click()
On Error GoTo Err_Command27_Click

Dim stDocName As String

stDocName = "17 CASES WITH ALL DEP POT EMANC Q"
DoCmd.OpenQuery stDocName, acNormal, acEdit


Dim stDocName As String

stDocName = " 18 CASES WITH ONE OR MORE CHILDREN UNDER 18 Q"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Dim stDocName As String

stDocName = "19 CASES WITH ALL DEP POT EMANC Without Matching 18 CASES WITH O"
DoCmd.OpenQuery stDocName, acNormal, acEdit


Dim stDocName As String

stDocName = "20 CASES WITH ALL CHILDREN POTENTIALLY EMANCIPATED"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_Command27_Click:
Exit Sub
 
you only need to do this once

Dim stDocName As String
 
I took all those lines out except the first one. Now I get a different compile error for the line For the line “Private Sub Command27_Click()”


"Label not defined"

It looks like this now

Private Sub Command27_Click()
On Error GoTo Err_Command27_Click

Dim stDocName As String

stDocName = "17 CASES WITH ALL DEP POT EMANC Q"
DoCmd.OpenQuery stDocName, acNormal, acEdit



stDocName = " 18 CASES WITH ONE OR MORE CHILDREN UNDER 18 Q"
DoCmd.OpenQuery stDocName, acNormal, acEdit


stDocName = "19 CASES WITH ALL DEP POT EMANC Without Matching 18 CASES WITH O"
DoCmd.OpenQuery stDocName, acNormal, acEdit



stDocName = "20 CASES WITH ALL CHILDREN POTENTIALLY EMANCIPATED"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_Command27_Click:
End Sub
 
ok

you are missing something
you have

On Error GoTo Err_Command27_Click

but you dont have an Err_Command27_Click in your code
 
I took all those lines out except the first one. Now I get a different compile error for the line For the line “Private Sub Command27_Click()”


"Label not defined"

It looks like this now

Private Sub Command27_Click()
On Error GoTo Err_Command27_Click

Dim stDocName As String

stDocName = "17 CASES WITH ALL DEP POT EMANC Q"
DoCmd.OpenQuery stDocName, acNormal, acEdit



stDocName = " 18 CASES WITH ONE OR MORE CHILDREN UNDER 18 Q"
DoCmd.OpenQuery stDocName, acNormal, acEdit


stDocName = "19 CASES WITH ALL DEP POT EMANC Without Matching 18 CASES WITH O"
DoCmd.OpenQuery stDocName, acNormal, acEdit



stDocName = "20 CASES WITH ALL CHILDREN POTENTIALLY EMANCIPATED"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_Command27_Click:
End Sub

the label error is highlighted
 
ok

you are missing something
you have

On Error GoTo Err_Command27_Click

but you dont have an Err_Command27_Click in your code


I don't understand where this is missing or were it goes
 
you are sdaying - if anything goes wrong in this code, jump to a particular point - but you dont have that point - hance an error

SO


Code:
Private Sub Command27_Click()
On Error GoTo Err_Command27_Click

Dim stDocName As String

stDocName = "17 CASES WITH ALL DEP POT EMANC Q"
DoCmd.OpenQuery stDocName, acNormal, acEdit



stDocName = " 18 CASES WITH ONE OR MORE CHILDREN UNDER 18 Q"
DoCmd.OpenQuery stDocName, acNormal, acEdit


stDocName = "19 CASES WITH ALL DEP POT EMANC Without Matching 18 CASES WITH O"
DoCmd.OpenQuery stDocName, acNormal, acEdit



stDocName = "20 CASES WITH ALL CHILDREN POTENTIALLY EMANCIPATED"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_Command27_Click:
'include this, otherwise the code falls into the error handler
[COLOR="Red"]exit sub[/COLOR]


'this is the error handler - you can make this more complex. you can test the nature of the error, and do different things depending.
[COLOR="red"]Err_Command27_Click:
msgbox("Error encountered")[/COLOR]



End Sub
 
how did you create this button?

Your code needs to look something like
Code:
[/COLOR][COLOR=Black]
    [/COLOR][COLOR=Black]Private Sub Command27_Click()
On Error GoTo [/COLOR][COLOR=Black]Err_Command27_Click
[/COLOR][COLOR=Black]Dim stDocName As String

    stDocName = "17 CASES WITH ALL DEP POT EMANC Q"
    DoCmd.OpenQuery stDocName, acNormal, acEdit



    stDocName = " 18 CASES WITH ONE OR MORE CHILDREN UNDER 18 Q"
    DoCmd.OpenQuery stDocName, acNormal, acEdit


    stDocName = "19 CASES WITH ALL DEP POT EMANC Without Matching 18 CASES WITH O"
    DoCmd.OpenQuery stDocName, acNormal, acEdit



    stDocName = "20 CASES WITH ALL CHILDREN POTENTIALLY EMANCIPATED"
    DoCmd.OpenQuery stDocName, acNormal, acEdit

GOTO  [/COLOR][COLOR=Black]Exit_Command27_Click

[/COLOR][COLOR=Black]Err_Command27_Click:
    MsgBox Err.Description
    Resume [/COLOR][COLOR=Black]Exit_Command27_Click

Exit_Command27_Click:
    End Sub[/COLOR]
 

Users who are viewing this thread

Back
Top Bottom