NoOOOOOOOOOOOO . I Think problem in after finish loop .the Do-while loop before that line forces rs to reach Eof .so let me know .How Should i put the update Statement Inside the Loop. so that it updates together with insert .The error is quite self explanitory and very obvious. It means that you are trying to insert duplicate values inside a field in which you cannot
Code:Public Sub InsertDailySales(ByRef con As ADODB.Connection, ByRef rs As ADODB.Recordset) Dim tempdate As Date Dim strMsg$, StrMsgSales$ Dim TotalValue# Dim totalQty% On Error GoTo errhnd Dim TempSerial As String TempSerial = "" rs.MoveFirst Do While Not rs.EOF If TempSerial <> rs!saleserial Then TempSerial = rs!saleserial If TempSerial <> "" Then con.Execute "Insert into interface.dbo.CNK_dailysales(Storeid,Saleserial,SaleInternalDate,dumpdate,nettotal) values('" & rs!StoreId & "','" & rs!saleserial & "','" & Format(rs!saleinternaldate, "YYYY-MM-DD") & "','" & Format(Now(), "YYYY-MM-DD HH:MM:SS") & "','" & "0" & "')" End If End If rs.MoveNext Loop strMsg = strMsg & rs!StoreId & " Total Sales" & vbTab & CDbl(TotalValue) & vbTab & " Total Qty" & vbTab & CInt(totalQty) & vbNewLine StrMsgSales = StrMsgSales & rs!StoreId & " Total Sales" & vbTab & CDbl(TotalValue) & vbTab & " Total Qty" & vbTab & CInt(totalQty) & vbNewLine ' Updating the Generated Files Date time Informations con.Execute "Update CNK_Stores set LastSaleDate='" & Format(DateAdd("d", 1, tempdate), "YYYY-MM-DD") & "' where INF_CODE='" & rs!StoreId & "'" errhnd: Debug.Print Err.Description ' Err.Clear ' On Error GoTo 0 End Sub![]()





Reply With Quote