Dim datAdapt As New OleDb.OleDbDataAdapter("Select * From Weekly_Customers; " & _
"Select * From Weekly_Receipts", Conn)
Dim commBuild As New OleDb.OleDbCommandBuilder(datAdapt)
Dim datset As New Data.DataSet
Dim datrow As Data.DataRow
commSQL1.CommandText = "Delete From Weekly_customers"
datRead1 = commSQL1.ExecuteReader
datRead1.Close()
commSQL.CommandText = "Select * From Invoice_customers Where Inv_Cust_ID = '" & _
strEmailCustID & "' and Inv_Statement_Date = '" & Format(dteEmailDate, "MM/dd/yyyy") & "'"
datRead = commSQL.ExecuteReader
If datRead.Read = True Then
blnDataCopy = True
datset.Clear()
datAdapt.Fill(datset, "Weekly_Customers")
datrow = datset.Tables("Weekly_Customers").NewRow
datrow.Item("Inv_Invoice_Number") = datRead.Item("Inv_Invoice_Number")
datrow.Item("Inv_Cust_Key") = datRead.Item("Inv_Cust_Key")
datrow.Item("Inv_Cust_ID") = datRead.Item("Inv_Cust_ID")
datrow.Item("Inv_Cust_Description") = datRead.Item("Inv_Cust_Description")
datrow.Item("Inv_Statement_Date") = Format(datRead.Item("Inv_Statement_Date"), "MM/dd/yyyy")
datrow.Item("Inv_Due_Date") = Format(datRead.Item("Inv_Due_Date"), "MM/dd/yyyy")
datrow.Item("Inv_Payments") = datRead.Item("Inv_Payments")
datrow.Item("Inv_Adjustments") = datRead.Item("Inv_Adjustments")
datrow.Item("Inv_Transactions") = datRead.Item("Inv_Transactions")
datrow.Item("Inv_Finance_Charge") = datRead.Item("Inv_Finance_Charge")
datrow.Item("Inv_Ending_Balance") = datRead.Item("Inv_Ending_Balance")
datrow.Item("Inv_Subtotal") = datRead.Item("Inv_Subtotal")
If IsDBNull(datRead.Item("Inv_Cust_Address_1")) = False Then
datrow.Item("Inv_Cust_Address_1") = Trim(datRead.Item("Inv_Cust_Address_1"))
End If
If IsDBNull(datRead.Item("Inv_Cust_Address_2")) = False Then
datrow.Item("Inv_Cust_Address_2") = datRead.Item("Inv_Cust_Address_2")
End If
If IsDBNull(datRead.Item("Inv_Cust_City")) = False Then
datrow.Item("Inv_Cust_City") = Trim(datRead.Item("Inv_Cust_City"))
End If
If IsDBNull(datRead.Item("Inv_Cust_State")) = False Then
commSQL2.CommandText = "Select State_Code From States Where State_Key = " & _
datRead.Item("Inv_Cust_State")
datread2 = commSQL2.ExecuteReader
If datread2.Read Then
If IsDBNull(datread2.Item("State_Code")) = False Then
datrow.Item("Inv_Cust_State") = datread2.Item("State_Code")
Else
datrow.Item("Inv_Cust_State") = "IN"
End If
Else
datrow.Item("Inv_Cust_State") = "IN"
End If
datread2.Close()
End If
If IsDBNull(datRead.Item("Inv_Cust_Zip")) = False Then
datrow.Item("Inv_Cust_Zip") = Trim(datRead.Item("Inv_Cust_Zip"))
End If
If IsDBNull(datRead.Item("Inv_Begin_Balance")) = False Then
datrow.Item("Inv_Begin_Balance") = datRead.Item("Inv_Begin_Balance")
End If
If IsDBNull(datRead.Item("Inv_PmtAdjTypeDTotal")) = False Then
datrow.Item("Inv_PmtAdjTypeDTotal") = datRead.Item("Inv_PmtAdjTypeDTotal")
End If
If IsDBNull(datRead.Item("Inv_TransactionsTypeDTotal")) = False Then
datrow.Item("Inv_TransactionsTypeDTotal") = datRead.Item("Inv_TransactionsTypeDTotal")
End If
If IsDBNull(datRead.Item("CustBal_TypeDBalance")) = False Then
datrow.Item("CustBal_TypeDBalance") = datRead.Item("CustBal_TypeDBalance")
End If
If IsDBNull(datRead.Item("Inv_Cust_Type_Key")) = False Then
datrow.Item("Inv_Cust_Type_Key") = datRead.Item("Inv_Cust_Type_Key")
End If
datset.Tables("Weekly_Customers").Rows.Add(datrow)
datAdapt.Update(datset, "Weekly_Customers")
Else
blnDataCopy = False
Exit Sub
End If
datRead.Close()
commSQL1.CommandText = "Delete From Weekly_Receipts"
datRead1 = commSQL1.ExecuteReader
datRead1.Close()
commSQL.CommandText = "Select * From Invoice_Receipts Where Receipt_Cust_ID = '" & _
strEmailCustID & "' and Receipt_Statement_Date = '" & Format(dteEmailDate, "MM/dd/yyyy") & "'"
datRead = commSQL.ExecuteReader
Do While datRead.Read
datset.Clear()
datAdapt.Fill(datset, "Weekly_Receipts")
datrow = datset.Tables("Weekly_Receipts").NewRow
If IsDBNull(datRead.Item("Receipt_ID")) = False Then datrow.Item("Receipt_ID") = datRead.Item("Receipt_ID")
If IsDBNull(datRead.Item("Receipt_TranCode_Description")) = False Then datrow.Item("Receipt_TranCode_Description") = datRead.Item("Receipt_TranCode_Description")
If IsDBNull(datRead.Item("Receipt_Amount")) = False Then datrow.Item("Receipt_Amount") = datRead.Item("Receipt_Amount")
If IsDBNull(datRead.Item("Receipt_Date")) = False Then datrow.Item("Receipt_Date") = datRead.Item("Receipt_Date")
If IsDBNull(datRead.Item("Receipt_Type")) = False Then datrow.Item("Receipt_Type") = datRead.Item("Receipt_Type")
If IsDBNull(datRead.Item("Receipt_Cust_ID")) = False Then datrow.Item("Receipt_Cust_ID") = datRead.Item("Receipt_Cust_ID")
If IsDBNull(datRead.Item("Receipt_Ref_No")) = False Then datrow.Item("Receipt_Ref_No") = datRead.Item("Receipt_Ref_No")
If IsDBNull(datRead.Item("Receipt_Statement_Date")) = False Then datrow.Item("Receipt_Statement_Date") = datRead.Item("Receipt_Statement_Date")
datset.Tables("Weekly_Receipts").Rows.Add(datrow)
datAdapt.Update(datset, "Weekly_Receipts")
Loop