Option Explicit '給与支払額フォーム '支給区分「0」固定 Private mobjWS() As Worksheet 'ワークシート 'mobjWS(0):Sheet5:給与データ 'mobjWS(1):Sheet1:雇用保険情報 'mobjWS(2):Sheet2:社員情報 'mobjWS(3):Sheet4:社員別給与体系情報 Private mlngFID As Long '外部キー Private mintNinzu As Integer '扶養親族数 Private mlngRow As Long 'レコード Private mintKeitai As Integer '雇用形態区分;「0」取締役;「1」一般;「2」パート;「3」アルバイト Private mintKubun As Integer '雇用保険区分;「0」A欄;「1」B欄;「2」未加入 Private mintZaisyoku As Integer '在職退職区分;「0」在職;「1」死亡退職;「2」普通退職 Const mintSikyu As Integer = 0 '支給区分 '前ページへボタン Private Sub cmdBack_Click() Me.mltSalary.Value = 0 Me.txtKyuyo1.SetFocus End Sub 'クリアボタン Private Sub cmdClear_Click() 'コントロールのリフレッシュ If cmdOk.Enabled = False Then cmdOk.Enabled = True Call NewData Call GetSyainList End Sub '削除ボタン Private Sub cmdDelete_Click() Dim intMsg As Integer 'メッセージ intMsg = MsgBox("削除しますか。", 32 + 0, "給与計算システム") If intMsg = 6 Then mobjWS(0).Cells(mlngRow, 1).EntireRow.Delete Call NewData Call GetSyainList End Sub '閉じるボタン Private Sub cmdEND_Click() Unload Me End Sub '次ページへボタン Private Sub cmdNext_Click() Me.mltSalary.Value = 1 Me.txtKyuyo13.SetFocus End Sub '登録ボタン Private Sub cmdOK_Click() Dim objText As MSForms.TextBox 'テキストボックス Dim intMsg As Integer 'メッセージの戻り値 Dim i As Integer '整数型カウンタ intMsg = MsgBox("登録しますか。", 32 + 4, "給与計算システム") '登録 If intMsg = 6 Then '支給日の検査 If IsDate(Me.txtDate.Text) = False Then GoTo DateErrorProc '金額の検査 For i = 1 To 24 Set objText = Controls("txtKyuyo" & CStr(i)) If objText.Text = "" Then objText.Text = 0 If IsNumeric(objText.Text) = False Then GoTo NumberErrorProc Next Call LetData MsgBox "正常に登録しました。", 64 + 0, "給与計算システム" Call NewData Call GetSyainList End If Set objText = Nothing Exit Sub NumberErrorProc: MsgBox "金額の値が不正です。", 16 + 0, "給与計算システム" Exit Sub DateErrorProc: MsgBox "支給日の値が不正です。", 16 + 0, "給与計算システム" End Sub '支給日リストを選択したとき Private Sub lstDate_Click() Dim objText As MSForms.TextBox 'テキストボックス Dim intMsg As Integer 'メッセージの戻り値 Dim lngID As Long '支給日の主キー Dim i As Integer '整数型カウンタ intMsg = MsgBox("訂正しますか。", 32 + 4, "給与計算システム") '「はい」のとき If intMsg = 6 Then For i = 1 To 24 Set objText = Controls("txtKyuyo" & CStr(i)) objText.Text = 0 Next '主キー取得 lngID = Me.lstDate.List(Me.lstDate.ListIndex, 0) 'ワークシートの値を取得 Call GetData(lngID) End If End Sub '社員リストを選択したとき Private Sub lstSyain_Click() Dim objText As MSForms.TextBox 'テキストボックス Dim lngRow1 As Long '社員情報レコード Dim lngRow2 As Long 'カレントレコード Dim datKisyu As Date '期首年月日 Dim datTaisyoku As Date '退職年月日 Dim i As Integer '整数型カウンタ Dim intMsg As Integer 'メッセージの戻り値 'カレントレコードの再取得 If mobjWS(0).Cells(1, 1).Value = "" Then mlngRow = 0 Else mlngRow = mobjWS(0).Cells(65536, 1).End(xlUp).Row End If For i = 1 To 24 Set objText = Controls("txtKyuyo" & CStr(i)) If objText.Enabled = False Then objText.Enabled = True Next '外部キーの取得 mlngFID = Me.lstSyain.List(Me.lstSyain.ListIndex, 0) '社員数の取得 lngRow1 = mobjWS(2).Cells(65536, 1).End(xlUp).Row '扶養親族数の取得 mobjWS(2).Activate lngRow2 = mobjWS(2).Range(Cells(1, 1), Cells(lngRow1, 1)).Find(mlngFID, Cells(lngRow1, 1), xlValues).Row For i = 14 To 26 mintNinzu = mintNinzu + CInt(mobjWS(2).Cells(lngRow2, i).Value) Next mintNinzu = mintNinzu - CInt(mobjWS(2).Cells(lngRow2, 16).Value) '老年者無効 '社員別給与体系の取得 Call GetTaikei '雇用形態区分の取得 mintKeitai = CInt(mobjWS(2).Cells(lngRow2, 4).Value) '在職退職区分の取得 mintZaisyoku = CInt(mobjWS(2).Cells(lngRow2, 6).Value) '退職者の評価 If mintZaisyoku > 1 Then datKisyu = CDate(mobjWS(2).Cells(lngRow2, 8).Value) datTaisyoku = CDate(mobjWS(2).Cells(lngRow2, 9).Value) If datKisyu < datTaisyoku Then 'If Now() > datTaisyoku Then GoTo TaisyokuErrorProc '退職者への対応 If Now() > datTaisyoku Then intMsg = MsgBox("退職者です。" & vbCrLf & "入力を続けますか...", 32 + 4, "給与計算システム") If intMsg = 7 Then For i = 0 To 3 Set mobjWS(i) = Nothing Next MsgBox "再入力ボタンをクリックして下さい。", 64 + 0, "給与計算システム" cmdOk.Enabled = False Exit Sub End If End If End If End If '初期値に対する源泉所得税と雇用保険料の計算 Call CalculateAuto '支給日リストの取得 Call GetDateList(mlngFID) If Me.cmdNext.Enabled = False Then Me.cmdNext.Enabled = True If Me.cmdBack.Enabled = False Then Me.cmdBack.Enabled = True If Me.mltSalary.page2.Enabled = False Then Me.mltSalary.page2.Enabled = True 'ファーカスを当てる With Me.txtDate If .Enabled = False Then .Enabled = True .SetFocus End With Set objText = Nothing Exit Sub TaisyokuErrorProc: MsgBox "すでに退職しています。", 16 + 0, "給与計算システム" End Sub 'フォーカスがあたったとき Private Sub txtDate_Enter() With Me.txtDate .BackColor = RGB(255, 255, 0) If .Text = "" Then .Text = Format$(Now, "yyyy/mm/dd") .SelStart = 0 .SelLength = Len(.Text) .IMEMode = 3 End With End Sub 'フォーカスが外れたとき Private Sub txtDate_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtDate .BackColor = RGB(255, 255, 255) .Text = Format$(.Text, "yyyy/mm/dd") .IMEMode = 0 End With End Sub '値が変更されたあと Private Sub txtKyuyo1_AfterUpdate() 'NULL値の検査 If Me.txtKyuyo1.Text = "" Then Me.txtKyuyo1.Text = 0 '源泉所得税と雇用保険料の計算 If Me.txtKyuyo1.Enabled = True Then Call CalculateAuto End Sub 'フォーカスが当ったとき(基本給) Private Sub txtKyuyo1_Enter() With Me.txtKyuyo1 .BackColor = RGB(255, 255, 0) .SelStart = 0 .SelLength = Len(.Text) .TextAlign = 1 .IMEMode = 3 End With End Sub 'フォーカスが外れたとき(基本給) Private Sub txtKyuyo1_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtKyuyo1 .BackColor = RGB(255, 255, 255) .TextAlign = 3 .Text = Format$(.Text, "#,##0") .IMEMode = 0 End With End Sub '値が変更されたあと Private Sub txtKyuyo10_AfterUpdate() 'NULL値の検査 If Me.txtKyuyo10.Text = "" Then Me.txtKyuyo10.Text = 0 '源泉所得税と雇用保険料の計算 If Me.txtKyuyo10.Enabled = True Then Call CalculateAuto End Sub 'フォーカスがあたったとき Private Sub txtKyuyo10_Enter() With Me.txtKyuyo10 .BackColor = RGB(255, 255, 0) .SelStart = 0 .SelLength = Len(.Text) .TextAlign = 1 .IMEMode = 3 End With End Sub 'フォーカスが外れたとき Private Sub txtKyuyo10_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtKyuyo10 .BackColor = RGB(255, 255, 255) .TextAlign = 3 .Text = Format$(.Text, "#,##0") .IMEMode = 0 End With End Sub '値が変更されたあと Private Sub txtKyuyo11_AfterUpdate() 'NULL値の検査 If Me.txtKyuyo11.Text = "" Then Me.txtKyuyo11.Text = 0 '源泉所得税と雇用保険料の計算 If Me.txtKyuyo11.Enabled = True Then Call CalculateAuto End Sub 'フォーカスがあたったとき Private Sub txtKyuyo11_Enter() With Me.txtKyuyo11 .BackColor = RGB(255, 255, 0) .SelStart = 0 .SelLength = Len(.Text) .TextAlign = 1 .IMEMode = 3 End With End Sub 'フォーカスが外れたとき Private Sub txtKyuyo11_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtKyuyo11 .BackColor = RGB(255, 255, 255) .TextAlign = 3 .Text = Format$(.Text, "#,##0") .IMEMode = 0 End With End Sub '値が変更されたあと Private Sub txtKyuyo12_AfterUpdate() 'NULL値の検査 If Me.txtKyuyo12.Text = "" Then Me.txtKyuyo12.Text = 0 '源泉所得税と雇用保険料の計算 If Me.txtKyuyo12.Enabled = True Then Call CalculateAuto End Sub 'フォーカスがあたったとき Private Sub txtKyuyo12_Enter() With Me.txtKyuyo12 .BackColor = RGB(255, 255, 0) .SelStart = 0 .SelLength = Len(.Text) .TextAlign = 1 .IMEMode = 3 End With End Sub 'フォーカスが外れたとき Private Sub txtKyuyo12_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtKyuyo12 .BackColor = RGB(255, 255, 255) .TextAlign = 3 .Text = Format$(.Text, "#,##0") .IMEMode = 0 End With End Sub '値が変更されたあと Private Sub txtKyuyo13_AfterUpdate() 'NULL値の検査 If Me.txtKyuyo13.Text = "" Then Me.txtKyuyo13.Text = 0 '源泉所得税と雇用保険料の計算 If Me.txtKyuyo13.Enabled = True Then Call CalculateAuto End Sub 'フォーカスがあたったとき Private Sub txtKyuyo13_Enter() With Me.txtKyuyo13 .BackColor = RGB(255, 255, 0) .SelStart = 0 .SelLength = Len(.Text) .TextAlign = 1 .IMEMode = 3 End With End Sub 'フォーカスが外れたとき Private Sub txtKyuyo13_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtKyuyo13 .BackColor = RGB(255, 255, 255) .TextAlign = 3 .Text = Format$(.Text, "#,##0") .IMEMode = 0 End With End Sub '値が変更されたあと Private Sub txtKyuyo14_AfterUpdate() 'NULL値の検査 If Me.txtKyuyo14.Text = "" Then Me.txtKyuyo14.Text = 0 '源泉所得税と雇用保険料の計算 If Me.txtKyuyo14.Enabled = True Then Call CalculateAuto End Sub 'フォーカスがあたったとき Private Sub txtKyuyo14_Enter() With Me.txtKyuyo14 .BackColor = RGB(255, 255, 0) .SelStart = 0 .SelLength = Len(.Text) .TextAlign = 1 .IMEMode = 3 End With End Sub 'フォーカスが外れたとき Private Sub txtKyuyo14_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtKyuyo14 .BackColor = RGB(255, 255, 255) .TextAlign = 3 .Text = Format$(.Text, "#,##0") .IMEMode = 0 End With End Sub '値が変更されたあと Private Sub txtKyuyo15_AfterUpdate() 'NULL値の検査 If Me.txtKyuyo15.Text = "" Then Me.txtKyuyo15.Text = 0 '源泉所得税と雇用保険料の計算 If Me.txtKyuyo15.Enabled = True Then Call CalculateAuto End Sub 'フォーカスがあたったとき Private Sub txtKyuyo15_Enter() With Me.txtKyuyo15 .BackColor = RGB(255, 255, 0) .SelStart = 0 .SelLength = Len(.Text) .TextAlign = 1 .IMEMode = 3 End With End Sub 'フォーカスが外れたとき Private Sub txtKyuyo15_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtKyuyo15 .BackColor = RGB(255, 255, 255) .TextAlign = 3 .Text = Format$(.Text, "#,##0") .IMEMode = 0 End With End Sub '値が変更されたあと Private Sub txtKyuyo16_AfterUpdate() 'NULL値の検査 If Me.txtKyuyo16.Text = "" Then Me.txtKyuyo16.Text = 0 '差引 If Me.txtKyuyo16.Enabled = True Then Call CalculateKingaku End Sub 'フォーカスがあたったとき Private Sub txtKyuyo16_Enter() With Me.txtKyuyo16 .BackColor = RGB(255, 255, 0) .SelStart = 0 .SelLength = Len(.Text) .TextAlign = 1 .IMEMode = 3 End With End Sub 'フォーカスが外れたとき Private Sub txtKyuyo16_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtKyuyo16 .BackColor = RGB(255, 255, 255) .TextAlign = 3 .Text = Format$(.Text, "#,##0") .IMEMode = 0 End With End Sub '値が変更されたあと Private Sub txtKyuyo17_AfterUpdate() 'NULL値の検査 If Me.txtKyuyo17.Text = "" Then Me.txtKyuyo17.Text = 0 '差引 If Me.txtKyuyo17.Enabled = True Then Call CalculateKingaku End Sub 'フォーカスがあたったとき Private Sub txtKyuyo17_Enter() With Me.txtKyuyo17 .BackColor = RGB(255, 255, 0) .SelStart = 0 .SelLength = Len(.Text) .TextAlign = 1 .IMEMode = 3 End With End Sub 'フォーカスが外れたとき Private Sub txtKyuyo17_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtKyuyo17 .BackColor = RGB(255, 255, 255) .TextAlign = 3 .Text = Format$(.Text, "#,##0") .IMEMode = 0 End With End Sub '値が変更されたあと Private Sub txtKyuyo18_AfterUpdate() 'NULL値の検査 If Me.txtKyuyo18.Text = "" Then Me.txtKyuyo18.Text = 0 '差引 If Me.txtKyuyo18.Enabled = True Then Call CalculateKingaku End Sub 'フォーカスがあたったとき Private Sub txtKyuyo18_Enter() With Me.txtKyuyo18 .BackColor = RGB(255, 255, 0) .SelStart = 0 .SelLength = Len(.Text) .TextAlign = 1 .IMEMode = 3 End With End Sub 'フォーカスが外れたとき Private Sub txtKyuyo18_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtKyuyo18 .BackColor = RGB(255, 255, 255) .TextAlign = 3 .Text = Format$(.Text, "#,##0") .IMEMode = 0 End With End Sub '値が変更されたあと Private Sub txtKyuyo19_AfterUpdate() 'NULL値の検査 If Me.txtKyuyo19.Text = "" Then Me.txtKyuyo19.Text = 0 '差引 If Me.txtKyuyo19.Enabled = True Then Call CalculateKingaku End Sub 'フォーカスがあたったとき Private Sub txtKyuyo19_Enter() With Me.txtKyuyo19 .BackColor = RGB(255, 255, 0) .SelStart = 0 .SelLength = Len(.Text) .TextAlign = 1 .IMEMode = 3 End With End Sub 'フォーカスが外れたとき Private Sub txtKyuyo19_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtKyuyo19 .BackColor = RGB(255, 255, 255) .TextAlign = 3 .Text = Format$(.Text, "#,##0") .IMEMode = 0 End With End Sub '値が変更されたあと Private Sub txtKyuyo2_AfterUpdate() 'NULL値の検査 If Me.txtKyuyo2.Text = "" Then Me.txtKyuyo2.Text = 0 '源泉所得税と雇用保険料の計算 If Me.txtKyuyo2.Enabled = True Then Call CalculateAuto End Sub 'フォーカスが当ったとき(職務手当) Private Sub txtKyuyo2_Enter() With Me.txtKyuyo2 .BackColor = RGB(255, 255, 0) .SelStart = 0 .SelLength = Len(.Text) .TextAlign = 1 .IMEMode = 3 End With End Sub 'フォーカスが外れたとき(職務手当) Private Sub txtKyuyo2_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtKyuyo2 .BackColor = RGB(255, 255, 255) .TextAlign = 3 .Text = Format$(.Text, "#,##0") .IMEMode = 0 End With End Sub '値が変更になったあと Private Sub txtKyuyo20_AfterUpdate() 'NULL値の検査 If Me.txtKyuyo20.Text = "" Then Me.txtKyuyo20.Text = 0 '差引 If Me.txtKyuyo20.Enabled = True Then Call CalculateKingaku End Sub 'フォーカスがあたったとき Private Sub txtKyuyo20_Enter() With Me.txtKyuyo20 .BackColor = RGB(255, 255, 0) .SelStart = 0 .SelLength = Len(.Text) .TextAlign = 1 .IMEMode = 3 End With End Sub 'フォーカスが外れたとき Private Sub txtKyuyo20_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtKyuyo20 .BackColor = RGB(255, 255, 255) .TextAlign = 3 .Text = Format$(.Text, "#,##0") .IMEMode = 0 End With End Sub '値が変更されたあと Private Sub txtKyuyo21_AfterUpdate() 'NULL値の検査 If Me.txtKyuyo21.Text = "" Then Me.txtKyuyo21.Text = 0 '差引 If Me.txtKyuyo21.Enabled = True Then Call CalculateKingaku End Sub 'フォーカスがあたったとき Private Sub txtKyuyo21_Enter() With Me.txtKyuyo21 .BackColor = RGB(255, 255, 0) .SelStart = 0 .SelLength = Len(.Text) .TextAlign = 1 .IMEMode = 3 End With End Sub 'フォーカスが外れたとき Private Sub txtKyuyo21_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtKyuyo21 .BackColor = RGB(255, 255, 255) .TextAlign = 3 .Text = Format$(.Text, "#,##0") .IMEMode = 0 End With End Sub 'フォーカスがあたったとき Private Sub txtKyuyo22_Enter() With Me.txtKyuyo22 .BackColor = RGB(255, 255, 0) .SelStart = 0 .SelLength = Len(.Text) .TextAlign = 1 .IMEMode = 3 End With End Sub 'フォーカスが外れたとき Private Sub txtKyuyo22_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtKyuyo22 .BackColor = RGB(255, 255, 255) .TextAlign = 3 .Text = Format$(.Text, "#,##0") .IMEMode = 0 End With End Sub 'フォーカスがあたったとき Private Sub txtKyuyo23_Enter() With Me.txtKyuyo23 .BackColor = RGB(255, 255, 0) .SelStart = 0 .SelLength = Len(.Text) .TextAlign = 1 .IMEMode = 3 End With End Sub 'フォーカスが外れたとき Private Sub txtKyuyo23_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtKyuyo23 .BackColor = RGB(255, 255, 255) .SelStart = 0 .SelLength = Len(.Text) .Text = Format$(.Text, "#,##0") .TextAlign = 3 .IMEMode = 3 End With End Sub 'フォーカスがあたったとき Private Sub txtKyuyo24_Enter() With Me.txtKyuyo24 .BackColor = RGB(255, 255, 0) .SelStart = 0 .SelLength = Len(.Text) .TextAlign = 1 .IMEMode = 3 End With End Sub 'フォーカスが外れたとき Private Sub txtKyuyo24_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtKyuyo24 .BackColor = RGB(255, 255, 255) .SelStart = 0 .SelLength = Len(.Text) .Text = Format$(.Text, "#,##0") .TextAlign = 3 .IMEMode = 3 End With End Sub '値が変更されたあと Private Sub txtKyuyo3_AfterUpdate() 'NULL値の検査 If Me.txtKyuyo3.Text = "" Then Me.txtKyuyo3.Text = 0 '源泉所得税と雇用保険料の計算 If Me.txtKyuyo3.Enabled = True Then Call CalculateAuto End Sub 'フォーカスがあたったとき Private Sub txtKyuyo3_Enter() With Me.txtKyuyo3 .BackColor = RGB(255, 255, 0) .SelStart = 0 .SelLength = Len(.Text) .TextAlign = 1 .IMEMode = 3 End With End Sub 'フォーカスが外れたとき Private Sub txtKyuyo3_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtKyuyo3 .BackColor = RGB(255, 255, 255) .TextAlign = 3 .Text = Format$(.Text, "#,##0") .IMEMode = 0 End With End Sub '値が変更されたあと Private Sub txtKyuyo4_AfterUpdate() 'NULL値の検査 If Me.txtKyuyo4.Text = "" Then Me.txtKyuyo4.Text = 0 '源泉所得税と雇用保険料の計算 If Me.txtKyuyo4.Enabled = True Then Call CalculateAuto End Sub 'フォーカスがあったとき Private Sub txtKyuyo4_Enter() With Me.txtKyuyo4 .BackColor = RGB(255, 255, 0) .SelStart = 0 .SelLength = Len(.Text) .TextAlign = 1 .IMEMode = 3 End With End Sub 'フォーカスが外れたとき Private Sub txtKyuyo4_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtKyuyo4 .BackColor = RGB(255, 255, 255) .TextAlign = 3 .Text = Format$(.Text, "#,##0") .IMEMode = 0 End With End Sub '値が変更されたあと Private Sub txtKyuyo5_AfterUpdate() 'NULL値の検査 If Me.txtKyuyo5.Text = "" Then Me.txtKyuyo5.Text = 0 '源泉所得税と雇用保険料の計算 If Me.txtKyuyo5.Enabled = True Then Call CalculateAuto End Sub 'フォーカスがあたったとき Private Sub txtKyuyo5_Enter() With Me.txtKyuyo5 .BackColor = RGB(255, 255, 0) .SelStart = 0 .SelLength = Len(.Text) .TextAlign = 1 .IMEMode = 3 End With End Sub 'フォーカスが外れたとき Private Sub txtKyuyo5_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtKyuyo5 .BackColor = RGB(255, 255, 255) .TextAlign = 3 .Text = Format$(.Text, "#,##0") .IMEMode = 0 End With End Sub '値が変更されたとき Private Sub txtKyuyo6_AfterUpdate() 'NULL値の検査 If Me.txtKyuyo6.Text = "" Then Me.txtKyuyo6.Text = 0 '源泉所得税と雇用保険料の計算 If Me.txtKyuyo6.Enabled = True Then Call CalculateAuto End Sub 'フォーカスがあたったとき Private Sub txtKyuyo6_Enter() With Me.txtKyuyo6 .BackColor = RGB(255, 255, 0) .SelStart = 0 .SelLength = Len(.Text) .TextAlign = 1 .IMEMode = 3 End With End Sub 'フォーカスが外れたとき Private Sub txtKyuyo6_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtKyuyo6 .BackColor = RGB(255, 255, 255) .TextAlign = 3 .Text = Format$(.Text, "#,##0") .IMEMode = 0 End With End Sub '値が変更されたあと Private Sub txtKyuyo7_AfterUpdate() 'NULL値の検査 If Me.txtKyuyo7.Text = "" Then Me.txtKyuyo7.Text = 0 '源泉所得税と雇用保険料の計算 If Me.txtKyuyo7.Enabled = True Then Call CalculateAuto End Sub 'フォーカスがあたったとき Private Sub txtKyuyo7_Enter() With Me.txtKyuyo7 .BackColor = RGB(255, 255, 0) .SelStart = 0 .SelLength = Len(.Text) .TextAlign = 1 .IMEMode = 3 End With End Sub 'フォーカスが外れたとき Private Sub txtKyuyo7_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtKyuyo7 .BackColor = RGB(255, 255, 255) .TextAlign = 3 .Text = Format$(.Text, "#,##0") .IMEMode = 0 End With End Sub '値が変更されたあと Private Sub txtKyuyo8_AfterUpdate() 'NULL値の検査 If Me.txtKyuyo8.Text = "" Then Me.txtKyuyo8.Text = 0 '源泉所得税と雇用保険料の計算 If Me.txtKyuyo8.Enabled = True Then Call CalculateAuto End Sub 'フォーカスがあたったとき Private Sub txtKyuyo8_Enter() With Me.txtKyuyo8 .BackColor = RGB(255, 255, 0) .SelStart = 0 .SelLength = Len(.Text) .TextAlign = 1 .IMEMode = 3 End With End Sub 'フォーカスが外れたとき Private Sub txtKyuyo8_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtKyuyo8 .BackColor = RGB(255, 255, 255) .TextAlign = 3 .Text = Format$(.Text, "#,##0") .IMEMode = 0 End With End Sub '値が変更されたあと Private Sub txtKyuyo9_AfterUpdate() 'NULL値の検査 If Me.txtKyuyo9.Text = "" Then Me.txtKyuyo9.Text = 0 '源泉所得税と雇用保険料の計算 If Me.txtKyuyo9.Enabled = True Then Call CalculateAuto End Sub 'フォーカスがあたったき Private Sub txtKyuyo9_Enter() With Me.txtKyuyo9 .BackColor = RGB(255, 255, 0) .SelStart = 0 .SelLength = Len(.Text) .TextAlign = 1 .IMEMode = 3 End With End Sub 'フォーカスが外れたとき Private Sub txtKyuyo9_Exit(ByVal Cancel As MSForms.ReturnBoolean) With Me.txtKyuyo9 .BackColor = RGB(255, 255, 255) .TextAlign = 3 .Text = Format$(.Text, "#,##0") .IMEMode = 0 End With End Sub 'フォームロード時 Private Sub UserForm_Initialize() '初期値 Call NewData '社員リストを取得 Call GetSyainList '項目の取得 Call GetKoumoku End Sub 'フォームクローズ時 Private Sub UserForm_Terminate() Dim i As Integer '配列の開放 If IsEmpty(mobjWS) = True Then Erase mobjWS 'オブジェクトの開放 For i = 0 To 3 Set mobjWS(i) = Nothing Next End Sub '源泉所得税/雇用保険料の計算 Private Sub CalculateAuto() Dim objText As MSForms.TextBox 'テキストボックス Dim lngSyakai As Long '社会保険料 Dim i As Integer '整数型カウンタ '雇用保険 If mintKubun < 2 Then Call CalculateKoyou '社会保険料の計算 For i = 13 To 16 Set objText = Controls("txtKyuyo" & CStr(i)) lngSyakai = lngSyakai + CLng(objText.Text) Next '源泉所得税 Call CalculateZei(lngSyakai, mintNinzu) '差引 Call CalculateKingaku Set objText = Nothing End Sub '社員別給与体系の取得 Private Sub GetTaikei() Dim clsTaikei As clsSalary '給与体系クラス Dim objText As MSForms.TextBox 'テキストボックス Dim A() As Variant 'データ Dim lngRow As Long '給与体系レコード Dim i As Integer '整数型カウンタ Dim j As Long 'データ数 On Error GoTo ErrorProc ReDim A(24) As Variant '配列再定義 '社員別給与体系テーブルのレコード取得 j = mobjWS(3).Cells(65536, 1).End(xlUp).Row mobjWS(3).Activate lngRow = mobjWS(3).Range(Cells(1, 2), Cells(j, 2)).Find(mlngFID, Cells(j, 2), xlValues).Row '給与体系クラスのインスタンス Set clsTaikei = New clsSalary clsTaikei.GetProperty mobjWS(3), lngRow, _ A(0), A(1), A(2), A(3), A(4), A(5), A(6), A(7), A(8), A(9), A(10), A(11), A(12), _ A(13), A(14), A(15), A(16), A(17), A(18), A(19), A(20), A(21), A(22), A(23), A(24) For i = 1 To 21 Set objText = Controls("txtKyuyo" & CStr(i)) With objText .Text = Format$(A(i + 3), "#,##0") .TextAlign = 3 End With Next '配列の開放 If IsEmpty(A) = True Then Erase A 'クラスの開放 Set clsTaikei = Nothing Set objText = Nothing Exit Sub ErrorProc: For i = 1 To 21 Set objText = Controls("txtKyuyo" & CStr(i)) With objText .Text = 0 .TextAlign = 3 End With Next Set objText = Nothing End Sub 'ワークシートデータの取得 Private Sub GetData(ByVal lngPID As Long) '引数[lngPID]:主キー Dim clsKyuyo As clsSalary '給与クラス Dim A() As Variant 'データ Dim objText As MSForms.TextBox 'テキストボックス Dim lngRow As Long 'カレントレコード Dim i As Long '長整数型カウンタ ReDim A(24) As Variant '配列再定義 'レコードの取得 If mobjWS(0).Cells(1, 1).Value = "" Then mlngRow = 0 Else mlngRow = mobjWS(0).Cells(65536, 1).End(xlUp).Row End If '支給日IDと一致するレコードの取得 mobjWS(0).Activate lngRow = mobjWS(0).Range(Cells(1, 1), Cells(mlngRow, 1)).Find(lngPID, Cells(mlngRow, 1), xlValues).Row 'カレントレコードの移動 mlngRow = lngRow - 1 '給与クラスのインスタンス Set clsKyuyo = New clsSalary 'ワークシートの値の取得 clsKyuyo.GetProperty mobjWS(0), mlngRow + 1, A(0), A(1), A(2), A(3), A(4), A(5), A(6), A(7), A(8), A(9), _ A(10), A(11), A(12), A(13), A(14), A(15), A(16), A(17), A(18), A(19), A(20), A(21), A(22), _ A(23), A(24) Me.txtDate.Text = Format$(A(3), "yyyy/mm/dd") For i = 1 To 21 Set objText = Controls("txtKyuyo" & CStr(i)) objText.Text = Format$(A(i + 3), "#,##0") Next Call CalculateKingaku '配列の開放 If IsEmpty(A) = True Then Erase A 'クラスの開放 Set clsKyuyo = Nothing 'オブジェクトの開放 Set objText = Nothing End Sub 'ワークシートへ書き出し Private Sub LetData() Dim clsKyuyo As clsSalary '給与クラス Dim objText As MSForms.TextBox 'テキストボックス Dim A() As Variant 'データ格納 Dim i As Integer '整数型カウンタ Const intNextIndex As Integer = 1 'インデックス自動附番 ReDim A(24) As Variant '配列再定義 'フォームのデータを配列に格納 '主キー If mlngRow > 0 Then A(0) = CLng(mobjWS(0).Cells(mlngRow, 1).Value) + intNextIndex ElseIf mlngRow = 0 Then A(0) = CLng(1) Else GoTo ErrorProc End If '空白テキストボックスのNULL値を回避 For i = 1 To 24 Set objText = Controls("txtKyuyo" & CStr(i)) If objText.Text = "" Then objText.Text = 0 Next A(1) = Me.lstSyain.List(Me.lstSyain.ListIndex, 0) '外部キー A(2) = mintSikyu A(3) = CDate(Me.txtDate.Text) For i = 1 To 21 Set objText = Controls("txtKyuyo" & CStr(i)) A(i + 3) = CLng(objText.Text) Next '給与クラスのインスタンス Set clsKyuyo = New clsSalary 'プロパティへ格納 clsKyuyo.LetProperty mobjWS(0), mlngRow + 1, A(0), A(1), A(2), A(3), A(4), A(5), A(6), A(7), A(8), A(9), _ A(10), A(11), A(12), A(13), A(14), A(15), A(16), A(17), A(18), A(19), A(20), A(21), _ A(22), A(23), A(24) '配列の開放 If IsEmpty(A) = True Then Erase A 'クラスの開放 Set clsKyuyo = Nothing 'オブジェクトの開放 Set objText = Nothing Exit Sub ErrorProc: MsgBox "社員が選択されていません。" & vbCrLf & "社員リストから選択して下さい。", 48 + 0, "給与計算システム" End Sub '雇用保険計算 Private Sub CalculateKoyou() Dim clsKoyouHoken As clsKoyou '雇用保険クラス Dim clsNum As clsNumber '給与総額クラス Dim objText As MSForms.TextBox 'テキストボックス Dim i As Integer '整数型カウンタ '-----edit at 2004/12/30 Dim datNow As Date '現在の日付 Dim datBirth As Date '生年月日 Dim intNenrei As Integer '満年齢 Dim clsTosi As clsNenrei '年齢計算クラス datNow = CDate(Me.txtDate.Text) datBirth = CDate(lstSyain.List(Me.lstSyain.ListIndex, 3)) '年齢計算クラス Set clsTosi = New clsNenrei Call clsTosi.GetData(datBirth, datNow) intNenrei = clsTosi.Nenrei '---------- '雇用形態の検査 If mintKeitai = 0 Or mintKeitai = 3 Then Exit Sub '給与総額クラスのインスタンス Set clsNum = New clsNumber '給与合計 For i = 1 To 12 Set objText = Controls("txtKyuyo" & CStr(i)) clsNum.Number = clsNum.Number + CDbl(objText.Text) Next '雇用保険クラスのインスタンス Set clsKoyouHoken = New clsKoyou If intNenrei > 65 Then Me.txtKyuyo16.Text = Format$(0, "#,##0") Else '計算結果をテキストボックスへ書き出し If intNenrei = 65 And Month(datNow) > 3 Then Me.txtKyuyo16.Text = Format$(0, "#,##0") Else clsKoyouHoken.CalculateHoken CLng(clsNum.Number), mintKubun, mintSikyu Me.txtKyuyo16.Text = Format$(clsKoyouHoken.KoyouHoken, "#,##0") End If End If 'クラスの開放 Set clsKoyouHoken = Nothing Set clsNum = Nothing Set clsTosi = Nothing 'オブジェクトの開放 Set objText = Nothing End Sub '源泉所得税の計算 Private Sub CalculateZei(ByVal lngSyakai As Long, ByVal mintNinzu As Integer) '引数[lngSyakai]:社会保険料 '引数[mintNinzu]:扶養親族数 Dim clsZei As clsGensen '源泉所得税クラス Dim clsZei2 As clsOtu '乙欄税額クラス Dim clsNum As clsNumber '課税給与クラス Dim objText As MSForms.TextBox 'テキストボックス Dim f As Integer '甲乙区分フラグ Dim i As Integer '整数型カウンタ '在職の検査 '退職者への対応 'If mintZaisyoku > 0 Then GoTo ZaisyokuErrorProc '甲乙欄区分の取得 f = Me.lstSyain.List(Me.lstSyain.ListIndex, 2) '課税給与クラスのインスタンス Set clsNum = New clsNumber '課税給与合計 For i = 1 To 11 Set objText = Controls("txtKyuyo" & CStr(i)) clsNum.Number = clsNum.Number + CDbl(objText.Text) Next '源泉所得税クラスのインスタンス Set clsZei = New clsGensen '乙欄税額クラスのインスタンス Set clsZei2 = New clsOtu If f = 0 Then '甲欄 '計算結果をテキストボックスへ clsZei.CalculateZei CLng(clsNum.Number) - lngSyakai, mintNinzu Me.txtKyuyo17.Text = Format$(clsZei.Zei, "#,##0") ElseIf f = 1 Then '乙欄 clsZei2.CalculateZei CLng(clsNum.Number) - lngSyakai Me.txtKyuyo17.Text = Format$(clsZei2.Zei, "#,##0") Else Me.txtKyuyo17.Text = 0 End If 'クラスの開放 Set clsZei = Nothing Set clsZei2 = Nothing Set clsNum = Nothing 'オブジェクトの開放 Set objText = Nothing Exit Sub ZaisyokuErrorProc: MsgBox "退職者です。", 16 + 0, "給与計算システム" End Sub '集計 Private Sub CalculateKingaku() Dim objText As MSForms.TextBox 'テキストボックス Dim A() As Long 'データ Dim i As Integer '整数型カウンタ ReDim A(1) As Long '配列再定義 'テキストボックスのデータを取得 For i = 1 To 21 Set objText = Me.Controls("txtKyuyo" & CStr(i)) If i < 13 Then A(0) = A(0) + CLng(objText.Text) If i > 12 Then A(1) = A(1) + CLng(objText.Text) Next With Me .txtKyuyo22.Text = Format$(A(0), "#,##0") .txtKyuyo23.Text = Format$(A(1), "#,##0") .txtKyuyo24.Text = Format$(A(0) - A(1), "#,##0") End With '配列の開放 If IsEmpty(A) = True Then Erase A 'オブジェクトの開放 Set objText = Nothing End Sub '支給年月日取得 Private Sub GetDateList(ByVal lngID As Long) '引数[lngID]:外部キー(社員コード) Dim clsDateID() As clsList '支給年月日クラス Dim rngArea As Excel.Range '外部キーエリア Dim lngRow As Long 'レコード数 Dim A() As Variant 'データ Dim intKisyu As Integer '期首年月日 Dim intTarget As Integer '対象年月日 Dim i As Long '長整数型カウンタ Dim j As Long '長整数型カウンタ Dim k As Long '配列の要素数 '給与データの有無 If Me.lstDate.ListIndex <> -1 And mobjWS(0).Cells(1, 1).Value = "" Then GoTo BlankProc '期首年月日の取得 intKisyu = Year(CDate(mobjWS(1).Cells(3, 1).Value)) '外部キーの数 On Error GoTo ErrorProc mobjWS(0).Activate 'レコード数の取得 lngRow = mobjWS(0).Cells(65536, 1).End(xlUp).Row If lngRow < mlngRow Then lngRow = mlngRow Set rngArea = mobjWS(0).Range(Cells(1, 2), Cells(lngRow, 2)) k = Application.WorksheetFunction.CountIf(rngArea, lngID) ReDim clsDateID(k - 1) As clsList 'クラス再定義 ReDim A(k - 1, 1) As Variant '配列再定義 j = 0 For i = 0 To mlngRow - 1 '支給年月日及び支給区分の検査 If mobjWS(0).Cells(i + 1, 2).Value = lngID And mobjWS(0).Cells(i + 1, 3).Value = mintSikyu Then intTarget = Year(CDate(mobjWS(0).Cells(i + 1, 4).Value)) '支給範囲の検査 If intTarget = intKisyu Then '支給年月日クラスのインスタンス Set clsDateID(j) = New clsList clsDateID(j).GetData2 mobjWS(0), i + 1, 1, 3, -1 '配列に格納 A(j, 0) = clsDateID(j).id A(j, 1) = Format$(clsDateID(j).Hiduke, "yyyy/mm/dd") j = j + 1 End If End If Next With Me.lstDate .Clear .ColumnCount = 2 .List() = A End With '配列の開放 If IsEmpty(A) = True Then Erase A 'クラスの開放 For i = 0 To k - 1 Set clsDateID(i) = Nothing Next 'オブジェクトの開放 Set rngArea = Nothing On Error GoTo 0 Exit Sub BlankProc: MsgBox "訂正できる給与データはありません。" & vbCrLf & "給与データを入力して下さい。", 48 + 0, "給与計算システム" Exit Sub ErrorProc: With Me.lstDate .Clear .ListIndex = -1 End With End Sub '社員リストの取得 Private Sub GetSyainList() Dim clsSyainID() As clsList '社員リストクラス Dim A() As Variant 'データ Dim lngRow As Long '社員データ数 Dim i As Long '長整数型カウンタ Dim j As Long '配列要素数 '社員リストの有無 If mobjWS(2).Cells(1, 1).Value = "" Then GoTo BlankProc '配列要素数の取得 lngRow = mobjWS(2).Cells(65536, 1).End(xlUp).Row '退職の検査 j = 0 For i = 1 To lngRow 'If mobjWS(2).Cells(i, 6).Value = 0 Then j = j + 1 '退職者も含める j = j + 1 Next '要素がないとき If j < 1 Then Exit Sub ReDim clsSyainID(j - 1) As clsList 'クラス再定義 ReDim A(j - 1, 3) As Variant '配列再定義 j = 0 For i = 0 To lngRow - 1 '退職者も含める 'If mobjWS(2).Cells(i + 1, 6).Value = 0 Then '社員リストクラスのインスタンス Set clsSyainID(j) = New clsList '社員リストの取得 clsSyainID(j).GetData3 mobjWS(2), i + 1, 1, 2, 27, 7 '配列に格納 A(j, 0) = clsSyainID(j).id A(j, 1) = clsSyainID(j).Name A(j, 2) = clsSyainID(j).Number A(j, 3) = clsSyainID(j).Hiduke '-----edit at 2004/12/30 j = j + 1 'End If Next With Me.lstSyain .Clear .ColumnCount = 4 .List() = A End With If IsEmpty(A) = True Then Erase A 'クラスの開放 For i = 0 To j - 1 Set clsSyainID(i) = Nothing Next Exit Sub BlankProc: MsgBox "社員リストは空です。" & vbCrLf & "先に社員給与計算システムを登録して下さい。", 48 + 0, "給与計算システム" End Sub 'ユーザー定義項目の取得 Private Sub GetKoumoku() Dim objText As MSForms.TextBox 'テキストボックス Dim objLB As MSForms.Label 'ラベル Dim i As Integer '整数型カウンタ '項目の取得 For i = 1 To 10 '手当項目 If i < 6 Then Set objLB = Controls("lblKyuyo" & CStr(i + 6)) Set objText = Controls("txtKyuyo" & CStr(i + 6)) If mobjWS(1).Cells(4, i).Value <> "" Then With objLB .Caption = mobjWS(1).Cells(4, i).Value & " :" .TextAlign = 3 End With 'テキストボックスの表示 objText.Visible = True Else objText.Visible = False End If '控除項目 ElseIf i > 6 Then Set objLB = Controls("lblKyuyo" & CStr(i + 11)) Set objText = Controls("txtKyuyo" & CStr(i + 11)) If mobjWS(1).Cells(4, i - 1).Value <> "" Then With objLB .Caption = mobjWS(1).Cells(4, i - 1).Value & " :" .TextAlign = 3 End With 'テキストボックスの表示 objText.Visible = True Else objText.Visible = False End If End If Next Set objText = Nothing Set objLB = Nothing End Sub '初期値設定 Public Sub NewData() Dim objText As MSForms.TextBox 'テキストボックス Dim objLB As MSForms.Label 'ラベル Dim i As Integer '整数型カウンタ ReDim mobjWS(3) As Worksheet '配列再定義 'データワークシートの取得 Set mobjWS(0) = Workbooks(gstrName).Worksheets("Sheet5") '給与データ Set mobjWS(1) = Workbooks(gstrName).Worksheets("Sheet1") '雇用保険区分 Set mobjWS(2) = Workbooks(gstrName).Worksheets("Sheet2") '社員情報 Set mobjWS(3) = Workbooks(gstrName).Worksheets("Sheet4") '社員別給与体系 'モジュールレベル変数の初期化 mlngFID = 0 mintNinzu = 0 mlngRow = 0 mintKeitai = 0 mintKubun = 0 mintZaisyoku = 0 'レコードの取得 If mobjWS(0).Cells(1, 1).Value = "" Then mlngRow = 0 Else mlngRow = mobjWS(0).Cells(65536, 1).End(xlUp).Row End If '雇用保険区分の取得 If mobjWS(1).Cells(2, 2).Value = 1 Then mintKubun = mobjWS(1).Cells(2, 3).Value If mobjWS(1).Cells(2, 2).Value = 0 Then mintKubun = 2 For i = 1 To 24 'ラベルコントロール Set objLB = Me.Controls("lblKyuyo" & CStr(i)) If objLB.Caption <> "" Then objLB.TextAlign = 3 'テキストボックスコントロール Set objText = Me.Controls("txtKyuyo" & CStr(i)) 'NULL値回避 With objText .Text = 0 .TextAlign = 3 .Enabled = False End With Next With Me.txtDate .Text = Format$(Now, "yyyy/mm/dd") .Enabled = False End With Me.lblDate.TextAlign = 3 Me.cmdDelete.Enabled = False Me.cmdNext.Enabled = False Me.cmdBack.Enabled = False Me.mltSalary.page2.Enabled = False '支給日リスト With Me.lstDate .Clear .ColumnWidths = "0;72" .ListIndex = -1 .IMEMode = 3 End With '社員リスト With Me.lstSyain .Clear .ColumnWidths = "0;72;0" .ListIndex = -1 .IMEMode = 3 End With 'かならず1ページから If Me.mltSalary.Value > 0 Then Me.mltSalary.Value = 0 With Me.txtKyuyo1 .SelStart = 0 .SelLength = Len(.Text) End With Set objText = Nothing Set objLB = Nothing End Sub