Goto ErrorHandler give "label not defined" error

K

kontra

I am new to programming and not sure why I get that error

Function FuelChargeReport()
'***********************************
'written by Victoria K. on 10/24/06
'***********************************

On Error GoTo ErrorHandler

Dim i, n, x, f, firstForm, enddate
Dim connString
Dim startdate
Dim FinalString ' for modification of a SQL string to insert

connString = "[Insert Connection parameters]"


If Date = CDate(Month(Date) & "/1/" & Year(Date)) Then
startdate = Month(Date - 1) & "01" & Year(Date - 1)
Else: startdate = Month(Date) & "01" & Year(Date)
End If
enddate = CDate(Format(Date - 1, "mm/dd/yyyy"))

If Date = CDate(Month(Date) & "/1/" & Year(Date)) Then
n = CDate(Month(Date - 1) & "/01/" & Year(Date - 1))
Else: n = CDate(Month(Date) & "/01/" & Year(Date))
End If

i = n

Do Until i = enddate
i = i + 1
x = Format(i, "mmddyyyy")
f = "1" & Right(x, 2) & Left(x, 2) & Mid(x, 3, 2)
firstForm = " INGL# IN('404','509') and INDATE like " & f & " or " &
firstForm & ""
Loop

FinalString = Left(firstForm, Len(firstForm) - 3)

Dim rsInvoicem As ADODB.Recordset
Dim tbl2 As TableDef
Dim connTDC

Set connTDC = New ADODB.Connection
connTDC.Open "Provider=IBMDA400;Data Source = 192.168.1.3;User
ID=VAK;Password=KONTRA"
Set rsInvoicem = New ADODB.Recordset
rsInvoicem.ActiveConnection = connTDC
rsInvoicem.Open "SELECT INREF#, INLINE, INACCT, INDATE, INWARE, INCCTR,
INGL#, INMISP from QS36F.INVOICEM WHERE " + FinalString + ""


DoCmd.DeleteObject acTable, "tblFuelSurcharge1"

Set tbl2 = CurrentDb.CreateTableDef("tblFuelSurcharge1")

With tbl2
..Fields.Append .CreateField("InvoiceNum", dbText)
..Fields.Append .CreateField("LineNum", dbText)
..Fields.Append .CreateField("AccountNum", dbText)
..Fields.Append .CreateField("Date", dbText)
..Fields.Append .CreateField("Warehouse", dbText)
..Fields.Append .CreateField("CostCenter", dbText)
..Fields.Append .CreateField("GLAccount", dbText)
..Fields.Append .CreateField("Amount", dbDouble)
CurrentDb.TableDefs.Append tbl2
End With

While Not rsInvoicem.EOF
DoCmd.RunSQL "INSERT INTO tblFuelSurcharge1 VALUES ('" +
CStr(rsInvoicem.Fields(0).Value) + "','" + CStr(rsInvoicem.Fields(1).Value) +
"','" + CStr(rsInvoicem.Fields(2).Value) + "','" +
CStr(rsInvoicem.Fields(3).Value) + "','" + CStr(rsInvoicem.Fields(4).Value) +
"','" + CStr(rsInvoicem.Fields(5).Value) + "','" +
CStr(rsInvoicem.Fields(6).Value) + "','" + CDbl(rsInvoicem.Fields(7).Value) +
"')"

rsInvoicem.MoveNext
Wend

rsInvoicem.Close
connTDC.Close
End Function

Public Sub ErrorHandler()

DoCmd.RunMacro (Errors)

End Sub
 
M

Marshall Barton

kontra said:
I am new to programming and not sure why I get that error

Function FuelChargeReport()
'***********************************
'written by Victoria K. on 10/24/06
'***********************************

On Error GoTo ErrorHandler [snip]
rsInvoicem.Close
connTDC.Close
End Function

Public Sub ErrorHandler()

DoCmd.RunMacro (Errors)

End Sub


ErrHandler needs to be a label in the procedure, not a
separate procedure.

The standard procedure outline is:

Function FuelChargeReport()
Dim . . .
Dim ErrNo As Long, ErrDesc As String
On Error GoTo ErrorHandler

. . .

AllDone:
rsInvoicem.Close
connTDC.Close
Exit Function

ErrHandler:
ErrNo = Err.Number
ErrDesc = Err.Description
Select Case ErrNo
Case nnnn 'deal with error nnnn
. . .
Resume somelabel
Case mmmm 'deal with error mmmm
. . .
Resume somelabel
Case Else
MsgBox ErrNo & " - " & ErrDesc
Resume AllDone
End Select
End Function
 
K

kontra

Makes sense, thank you.
--
If at first you don''''''''t succeed, destroy all evidence that you tried.


Marshall Barton said:
kontra said:
I am new to programming and not sure why I get that error

Function FuelChargeReport()
'***********************************
'written by Victoria K. on 10/24/06
'***********************************

On Error GoTo ErrorHandler [snip]
rsInvoicem.Close
connTDC.Close
End Function

Public Sub ErrorHandler()

DoCmd.RunMacro (Errors)

End Sub


ErrHandler needs to be a label in the procedure, not a
separate procedure.

The standard procedure outline is:

Function FuelChargeReport()
Dim . . .
Dim ErrNo As Long, ErrDesc As String
On Error GoTo ErrorHandler

. . .

AllDone:
rsInvoicem.Close
connTDC.Close
Exit Function

ErrHandler:
ErrNo = Err.Number
ErrDesc = Err.Description
Select Case ErrNo
Case nnnn 'deal with error nnnn
. . .
Resume somelabel
Case mmmm 'deal with error mmmm
. . .
Resume somelabel
Case Else
MsgBox ErrNo & " - " & ErrDesc
Resume AllDone
End Select
End Function
 

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