|
全てのモジュールです。
宜しくお願いします。
Public Sub WT_予算B_作成()
Dim cN As ADODB.Connection
'費目マスタ
Dim rsH As ADODB.Recordset
'出張所マスタ
Dim rsSB As ADODB.Recordset
'メインテーブル
Dim rsTB As ADODB.Recordset
'ワークテーブル
Dim rsWB As ADODB.Recordset
Dim xSQL1 As String
Dim xSQL2 As String
Set cN = CurrentProject.Connection
Set rsH = New ADODB.Recordset
Set rsSB = New ADODB.Recordset
Set rsTB = New ADODB.Recordset
Set rsWB = New ADODB.Recordset
Set rsGBB = New ADODB.Recordset
rsH.Open "SELECT T_費目マスタ.* FROM T_費目マスタ " & _
"WHERE (((T_費目マスタ.除)<>1));", cN, adopkeyset, adLockReadOnly
rsSB.Open "SELECT T_出張所マスタ.* FROM T_出張所マスタ " & _
"WHERE (((T_出張所マスタ.除)<>1));", cN, adopkeyset, adLockReadOnly
rsTB.Open "SELECT T_予算B.* FROM T_予算B " & _
"WHERE (((T_予算B.期)=DLookUp('期','T_管理マスタ','ID=1')));", cN, adopkeyset, adLockOptimistic
rsWB.Open "WT_予算B", cN, adopkeyset, adLockOptimistic
'〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜
'WT_予算Bを初期化
'〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜
xSQL1 = "DELETE WT_予算B.* FROM WT_予算B;"
DoCmd.RunSQL xSQL1
'〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜
'T_予算BのデータをWT_予算Bに昨期予算を出張所編成に合わせて合計したデータを追加
'〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜
xSQL2 = "INSERT INTO WT_予算B ( 期, 出張所CD, 費目CD, 営現CD, 今1, 今2, 今3, 今4 ) " & _
"SELECT DLookUp('期','T_管理マスタ','ID=1') AS 新期, T_出張所マスタ.集計CD, T_予算B.費目CD, T_予算B.営現CD, Sum(T_予算B.今1) AS 今1の合計, Sum(T_予算B.今2) AS 今2の合計, Sum(T_予算B.今3) AS 今3の合計, Sum(T_予算B.今4) AS 今4の合計 " & _
"FROM T_出張所マスタ INNER JOIN T_予算B ON T_出張所マスタ.出張所CD = T_予算B.出張所CD " & _
"WHERE (((T_予算B.期) = DLookup('期', 'T_管理マスタ', 'ID=1') - 1)) " & _
"GROUP BY T_予算B.期, T_出張所マスタ.集計CD, T_予算B.費目CD, T_予算B.営現CD;"
DoCmd.RunSQL xSQL2
'〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜
'WT_予算BのデータをT_予算Bを追加
'〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜
rsWB.MoveFirst
Do Until rsTB.EOF
rsTB.MoveFirst
rsTB.Seek Array(rsWB![期], rsWB![出張所CD], rsWB![費目CD], rsWB![営現CD]), adSeekFirstEQ
If rsTB.EOF Then
rsTB.AddNew
rsTB![期] = rsWB![期]
rsTB![出張所CD] = rsWB![出張所CD]
rsTB![費目CD] = rsWB![費目CD]
rsTB![営現CD] = rsWB![営現CD]
rsTB.Update
End If
rsWB.MoveNext
Loop
rsH.Close
rsSB.Close
rsTB.Close
rsWB.Close
cN.Close
End Sub
|
|