|
winXP
Access2002なのですが rs1.Find "年度CD='" & rs2!年度CD & "'"
のところでレコードは削除されていますとメッセージが出てしまいます。
WT_年度予算Bにはレコードが追加できていてT_年度予算Bにレコードが追加できない状態です。わかる方がいらしたら宜しくお願いします。
Public Sub B_年度予算B_追加()
'**************************************************
'WT_年度予算Bに費目データを追加する
'**************************************************
Dim cn As ADODB.Connection
Dim rs1 As ADODB.Recordset
Dim rs2 As ADODB.Recordset
Dim xSQL1 As String 'WT_年度予算Bを初期化
Dim xSQL2 As String 'T_年度予算Bの年度CD適正化
Set cn = CurrentProject.Connection
Set rs1 = New ADODB.Recordset
Set rs2 = New ADODB.Recordset
rs1.Open "T_年度予算B", cn, adopkeyset, adLockOptimistic
rs2.Open "WT_年度予算B", cn, adopkeyset, adLockOptimistic
xSQL1 = "Delete * from WT_年度予算B;"
DoCmd.RunSQL xSQL1
xSQL2 = "UPDATE T_年度予算B SET T_年度予算B.年度CD = [期] & [出張所CD] & [費目CD];"
DoCmd.RunSQL xSQL2
'**************************************************
'WT_年度予算AへT_年度予算のデータ追加
'**************************************************
rs1.MoveFirst
Do Until rs1.EOF
If Int(rs1!期) = Int(Forms!F_Main!期.Value) - 1 Then
rs2.AddNew
rs2![年度CD] = Int(Forms!F_Main!期.Value) & rs1![出張所CD] & rs1![費目CD]
rs2![期] = Int(Forms!F_Main!期.Value)
rs2![費目CD] = rs1![費目CD]
rs2![出張所CD] = rs1![出張所CD]
rs2.Update
End If
rs1.MoveNext
Loop
'**************************************************
'T_年度予算BへWT_年度予算のデータ追加
'**************************************************
rs2.MoveFirst
Do Until rs2.EOF
rs1.Find "年度CD='" & rs2!年度CD & "'"
If rs1.EOF Then
rs1.AddNew
rs1![年度CD] = rs2![年度CD]
rs1![期] = rs2![期]
rs1![費目CD] = rs2![費目CD]
rs1![出張所CD] = rs2![出張所CD]
rs1.Update
End If
rs2.MoveNext
Loop
rs1.Close
rs2.Close
cn.Close
End Sub
|
|