插入不重復的資料
Dim x As String Dim date11 As Date
Dim cn As New Connection
Dim objrs2 As New Recordset
x = Format(DTP1.Value, "yyyymmdd") & "至" & Format(DTP2.Value, "yyyymmdd")
date11 = DTP1.Value
cn.Execute "DELETE from t_a where td013 between'" & Format(DTP1.Value, "yyyymmdd") & "' And '" & Format(DTP2.Value, "yyyymmdd") & "'"
For a = 0 To weeks - 1
tempdate = DateAdd("ww", a, date1) + 6
k = "insert into t_a select tda=" & a + 1 & ",date1='" & x & "',TD008,SUM(TD008),bhd=0,maxqty=0,remark='',td013=TD013 from COPTD where TD013 between '" & Format(DTP1.Value, "yyyymmdd") & "' AND '" & Format(DTP2.Value, "yyyymmdd") & "'group by TD008,TD013"
cn.Execute k
Next
For q = 0 To a
Set objrs2 = Nothing
objrs2.CursorLocation = adUseClient
If a = q Then
Set objrs = Nothing
objrs2.Open "select distinct tda,date1,count(td0081),td008,bhd=sum(td008)/625,maxqty,remark,td013 from t_a where td013 BETWEEN '" & Format(DTP1.Value, "yyyymmdd") & "' and '" & Format(DTP2.Value, "yyyymmdd") & "' group by tda,date1,td008,maxqty,remark,td013", cn, 3, 2
End If
Next
由於要將第幾周寫入進去,望高手調試,指教一下