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
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