(祝)東京オリンピック!

(祝)北京オリンピック!

カレンダーフォーム

Access カレンダーFORM

コントローの配置
1段目 年を減算するコマンドボタン[PY]
    年を表示するラベル[DYEAR]
    年を加算するコマンドボタン[NY]
    月を加算するコマンドボタン[PM]
    月を表示するラベル[DMONTH]
    月を加算するコマンドボタン[NM]
2段目~7段目
    日にちを表示するラベル[Dx] xは0から41までの数字
    1クリック目でラベルを窪み表示にして、窪み表示をクリックすると
    カレンダーは非表示になり、呼び出し元でプロパティ[DateNum][WeekNum]
    からシリアル値、Week値を取得します。
8段目 カレンダーを開いたときのデフォルト値に戻すコマンドボタン[bu初期]
    カレンダーを非表示して、呼び出し元でプロパティ[DateNum]の0を評価して
    処理します。
    カレンダーを閉じるコマンドボタン[bu閉じる]

COPY

  1. '----------------------------------------------------------------
  2. 'カレンダー
  3. '令和3年5月6日
  4. '----------------------------------------------------------------
  5. Option Compare Database
  6. Option Explicit
  7.  
  8. Private WithEvents myControls As C_Controls
  9.  
  10. Private Const SHIFT_MASK As Long = 1
  11.  
  12. Private Const FirstYobi As Long = vbSunday
  13.  
  14. Private HoldDate As Long
  15. Private HoldYear As Long
  16. Private HoldMonth As Long
  17. Private HoldDay As Long
  18.  
  19. Private Enum IncType
  20. Forward = 1
  21. Backward = -1
  22. End Enum
  23.  
  24. Private GetYobi As C_KyuZitu
  25.  
  26. Private Const IntvDay As String = "d"
  27. Private Const IntvMonth As String = "m"
  28. Private Const IntvYear As String = "yyyy"
  29. Private Const IntvWeek As String = "ww"
  30.  
  31. Private CurYear As Long
  32. Private CurMonth As Long
  33. Private CurDay As Long
  34.  
  35. Private DaysAndWeeks() As Long
  36. Private Yobi As Variant
  37. Private SelectDay As String
  38.  
  39. Public Property Get DateNum() As Long
  40. If CurYear = 0 Then
  41. DateNum = 0
  42. Else
  43. DateNum = DateSerial(CurYear, CurMonth, CurDay)
  44. End If
  45. End Property
  46.  
  47. Public Property Get WeekNum() As Long
  48. GetYobi.SetNumDate = DateSerial(CurYear, CurMonth, CurDay)
  49. WeekNum = GetYobi.WeekNum
  50. End Property
  51. '----------------------------------------------------------------
  52. '
  53. Private Sub Form_Load()
  54.  
  55. Dim Ctrl As Access.Control
  56. Dim I As Long
  57.  
  58. If Nz(Me.OpenArgs, "") = "" Then
  59. HoldDate = Date
  60. Else
  61. If IsDate(Me.OpenArgs) Then
  62. HoldDate = DateSerial(DatePart("YYYY", Me.OpenArgs), _
  63. DatePart("m", Me.OpenArgs), _
  64. DatePart("d", Me.OpenArgs))
  65. Else
  66. HoldDate = Date
  67. End If
  68. End If
  69.  
  70. HoldYear = Year(HoldDate)
  71. HoldMonth = Month(HoldDate)
  72. HoldDay = Day(HoldDate)
  73.  
  74. Set GetYobi = New C_KyuZitu
  75. GetYobi.pYear = HoldYear
  76.  
  77. CurYear = HoldYear
  78. CurMonth = HoldMonth
  79. CurDay = HoldDay
  80.  
  81. Set myControls = New C_Controls
  82. With myControls
  83. Set .Parent = Me
  84. .Init
  85. End With
  86.  
  87. Yobi = Array("日", "月", "火", "水", "木", "金", "土")
  88. For I = 0 To 6
  89. Me("Y" & I).Caption = Yobi((FirstYobi - 1 + I) Mod 7)
  90. Select Case I
  91. Case 0
  92. Me("Y" & I).ForeColor = vbRed
  93. Case 6
  94. Me("Y" & I).ForeColor = vbBlue
  95. End Select
  96. Next I
  97.  
  98. Call SetCurDisp
  99. Call DispDraw
  100.  
  101. End Sub
  102. '----------------------------------------------------------------
  103. '
  104. Private Sub Form_Close()
  105.  
  106. End Sub
  107. '----------------------------------------------------------------
  108. '
  109. Private Sub SetCurDisp()
  110.  
  111. Me.DMONTH.Caption = CurMonth
  112. Me.DYEAR.Caption = CurYear
  113.  
  114. End Sub
  115. '----------------------------------------------------------------
  116. '
  117. Private Sub DispDraw()
  118. Dim Ctrl As Access.Control
  119. Dim NewSelect As String
  120. Dim OneDayYobi As Long
  121. Dim OneDaySerial As Long
  122. Dim I As Long
  123.  
  124. GetYobi.pYear = CurYear
  125.  
  126. '選択月の最初の日のシリアル値
  127. OneDaySerial = DateSerial(CurYear, CurMonth, 1)
  128.  
  129. '選択月の最初の日の曜日
  130. OneDayYobi = Weekday(OneDaySerial, FirstYobi)
  131.  
  132. '配列にシリアル値をセット
  133. ReDim DaysAndWeeks(0 To 41)
  134. For I = 0 To UBound(DaysAndWeeks)
  135. DaysAndWeeks(I) = OneDaySerial - (OneDayYobi - 1) + I
  136. Next I
  137.  
  138. 'ラベルのキャプションに日にちをセット
  139. For I = 0 To UBound(DaysAndWeeks)
  140. Me("Day" & I).Caption = Day(DaysAndWeeks(I))
  141.  
  142. If Me.DMONTH.Caption <> Month(DaysAndWeeks(I)) Then
  143. Me("Day" & I).FontSize = 10
  144. Else
  145. Me("Day" & I).FontSize = 12
  146. End If
  147.  
  148. If Me("Day" & I).ForeColor <> InteriorColor(DaysAndWeeks(I)) Then
  149. Me("Day" & I).ForeColor = InteriorColor(DaysAndWeeks(I))
  150. End If
  151.  
  152. If DaysAndWeeks(I) = DateSerial(CurYear, CurMonth, CurDay) Then
  153. NewSelect = "Day" & I
  154. End If
  155. Next I
  156.  
  157. Call EffectDraw(NewSelect)
  158.  
  159. End Sub
  160. '----------------------------------------------------------------
  161. '
  162. Private Sub EffectDraw(NewSelect As String)
  163.  
  164. If Len(SelectDay) > 0 Then
  165. If SelectDay <> NewSelect Then
  166. Me(SelectDay).SpecialEffect = acNormal
  167. End If
  168. End If
  169.  
  170. SelectDay = NewSelect
  171. Me(SelectDay).SpecialEffect = acEffectSunken
  172.  
  173. Me.Repaint
  174.  
  175. End Sub
  176. '----------------------------------------------------------------
  177. '
  178. Private Function InteriorColor(DrawDate As Long) As Long
  179.  
  180. GetYobi.SetNumDate = DrawDate
  181.  
  182. Select Case GetYobi.WeekNum
  183. Case 1, 10, 11, 12, 13
  184. InteriorColor = vbRed
  185. Case 7
  186. InteriorColor = vbBlue
  187. Case Else
  188. InteriorColor = vbBlack
  189. End Select
  190.  
  191. End Function
  192. '----------------------------------------------------------------
  193. '
  194. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  195.  
  196. Call ShiftKeys(KeyCode, Shift)
  197.  
  198. End Sub
  199. '----------------------------------------------------------------
  200. '
  201. Private Sub myControls_Click(myCont As Object)
  202.  
  203. Select Case myCont.Name
  204. Case "NM"
  205. Me.buDummy.SetFocus
  206. Call NextMonth
  207. Case "NY"
  208. Me.buDummy.SetFocus
  209. Call NextYear
  210. Case "PM"
  211. Me.buDummy.SetFocus
  212. Call PreviousMonth
  213. Case "PY"
  214. Me.buDummy.SetFocus
  215. Call PreviousYear
  216. Case "bu閉じる"
  217. Me.buDummy.SetFocus
  218. Call CloseForm(False)
  219. Case "bu初期"
  220. Me.buDummy.SetFocus
  221. CurYear = HoldYear
  222. CurMonth = HoldMonth
  223. CurDay = HoldDay
  224. Call SetCurDisp
  225. Call DispDraw
  226. Case "bu削除"
  227. Me.buDummy.SetFocus
  228. CurYear = 0
  229. Call CloseForm(True)
  230. Case Else
  231. Select Case True
  232. Case InStr(myCont.Name, "Day") = 1
  233. If myCont.SpecialEffect = acEffectSunken Then
  234. Call CloseForm(True)
  235. Else
  236. If CurMonth <> Month(DaysAndWeeks(Mid(myCont.Name, Len("Day") + 1))) Then
  237. Call ClickDate(myCont.Name)
  238. Call SetCurDisp
  239. Call DispDraw
  240. Else
  241. Call EffectDraw(myCont.Name)
  242. Call ClickDate(myCont.Name)
  243. End If
  244. End If
  245. End Select
  246. End Select
  247.  
  248. End Sub
  249. '----------------------------------------------------------------
  250. '
  251. Private Sub myControls_DblClick(myCont As Object, Cancel As Integer)
  252.  
  253. Select Case True
  254. Case InStr(myCont.Name, "Day") = 1
  255. Call EffectDraw(myCont.Name)
  256. Call ClickDate(myCont.Name)
  257. Call CloseForm(True)
  258. End Select
  259.  
  260. End Sub
  261. '----------------------------------------------------------------
  262. '
  263. Private Sub myControls_KeyDown(myCont As Object, KeyCode As Integer, Shift As Integer)
  264.  
  265. Select Case myCont.Name
  266. Case "PM", "NM", "PY", "NY", "bu閉じる", "bu初期", "bu削除"
  267. Call ShiftKeys(KeyCode, Shift)
  268. Case Else
  269. Select Case True
  270. Case InStr(myCont.Name, "Day") = 1
  271. Call ShiftKeys(KeyCode, Shift)
  272. End Select
  273. End Select
  274.  
  275. End Sub
  276. '----------------------------------------------------------------
  277. '
  278. Private Sub ShiftKeys(KeyCode As Integer, Shift As Integer)
  279. Dim ShiftDown As Boolean
  280.  
  281. ShiftDown = ((Shift And SHIFT_MASK) > 0)
  282.  
  283. Select Case KeyCode
  284. Case vbKeyEscape
  285. Call CloseForm(Hide:=False)
  286. Case vbKeyReturn
  287. Call CloseForm(Hide:=True)
  288. Case vbKeyHome
  289. If ShiftDown Then
  290. Call MoveToToday(False)
  291. Else
  292. Call MoveToToday(True)
  293. End If
  294. Case vbKeyPageUp
  295. If ShiftDown Then
  296. Call PreviousYear
  297. Else
  298. Call PreviousMonth
  299. End If
  300. Case vbKeyPageDown
  301. If ShiftDown Then
  302. Call NextYear
  303. Else
  304. Call NextMonth
  305. End If
  306. Case vbKeyRight
  307. If ShiftDown Then
  308. Call NextYear
  309. Else
  310. Call NextDay
  311. End If
  312. Case vbKeyLeft
  313. If ShiftDown Then
  314. Call PreviousYear
  315. Else
  316. Call PreviousDay
  317. End If
  318. Case vbKeyUp
  319. If ShiftDown Then
  320. Call PreviousMonth
  321. Else
  322. Call PreviousWeek
  323. End If
  324. Case vbKeyDown
  325. If ShiftDown Then
  326. Call NextMonth
  327. Else
  328. Call NextWeek
  329. End If
  330. End Select
  331.  
  332. KeyCode = 0
  333.  
  334. End Sub
  335. '----------------------------------------------------------------
  336. '
  337. Public Sub Today()
  338. Call MoveToToday(UseCurYear:=True)
  339. End Sub
  340. '----------------------------------------------------------------
  341. '
  342. Public Sub NextDay()
  343. Call ChangeDate(IntvDay, IncType.Forward)
  344. End Sub
  345. '----------------------------------------------------------------
  346. '
  347. Public Sub NextMonth()
  348. Call ChangeDate(IntvMonth, IncType.Forward)
  349. End Sub
  350. '----------------------------------------------------------------
  351. '
  352. Public Sub NextYear()
  353. Call ChangeDate(IntvYear, IncType.Forward)
  354. End Sub
  355. '----------------------------------------------------------------
  356. '
  357. Public Sub NextWeek()
  358. Call ChangeDate(IntvWeek, IncType.Forward)
  359. End Sub
  360. '----------------------------------------------------------------
  361. '
  362. Public Sub PreviousDay()
  363. Call ChangeDate(IntvDay, IncType.Backward)
  364. End Sub
  365. '----------------------------------------------------------------
  366. '
  367. Public Sub PreviousMonth()
  368. Call ChangeDate(IntvMonth, IncType.Backward)
  369. End Sub
  370. '----------------------------------------------------------------
  371. '
  372. Public Sub PreviousYear()
  373. Call ChangeDate(IntvYear, IncType.Backward)
  374. End Sub
  375. '----------------------------------------------------------------
  376. '
  377. Public Sub PreviousWeek()
  378. Call ChangeDate(IntvWeek, IncType.Backward)
  379. End Sub
  380. '----------------------------------------------------------------
  381. '
  382. Private Sub MoveToToday(UseCurYear As Boolean)
  383.  
  384. If UseCurYear Then
  385. CurYear = HoldYear
  386. End If
  387. CurMonth = HoldMonth
  388. CurDay = HoldDay
  389.  
  390. Call SetCurDisp
  391. Call DispDraw
  392.  
  393. End Sub
  394. '----------------------------------------------------------------
  395. '
  396. Private Sub ChangeDate(IntvStr As String, IT As IncType)
  397. Dim bufMonth As Integer
  398. Dim bufYear As Integer
  399. Dim bufDay As Integer
  400. Dim NewSelect As String
  401. Dim OLDDate As Long
  402. Dim NewDate As Long
  403. Dim Inc As Long
  404. Dim I As Long
  405.  
  406. If IT = Forward Then
  407. Inc = 1
  408. Else
  409. Inc = -1
  410. End If
  411. OLDDate = DateSerial(CurYear, CurMonth, CurDay)
  412. NewDate = DateAdd(IntvStr, Inc, OLDDate)
  413.  
  414. bufMonth = DatePart(IntvMonth, NewDate)
  415. bufYear = DatePart(IntvYear, NewDate)
  416. bufDay = DatePart(IntvDay, NewDate)
  417.  
  418. If CurMonth = bufMonth And _
  419. CurYear = bufYear Then
  420. CurDay = bufDay
  421. For I = 0 To UBound(DaysAndWeeks)
  422. If DaysAndWeeks(I) = DateSerial(CurYear, CurMonth, CurDay) Then
  423. NewSelect = "Day" & I
  424. End If
  425. Next I
  426.  
  427. Call EffectDraw(NewSelect)
  428. Else
  429. CurDay = bufDay
  430. CurMonth = bufMonth
  431. CurYear = bufYear
  432.  
  433. Call SetCurDisp
  434. Call DispDraw
  435. End If
  436.  
  437. End Sub
  438. '----------------------------------------------------------------
  439. '
  440. Private Sub CloseForm(Hide As Boolean)
  441.  
  442. If ThisFormSub() Then
  443. Exit Sub
  444. End If
  445.  
  446. If Hide Then
  447. Me.Visible = False
  448. Else
  449. DoCmd.CLOSE acForm, Me.Name, acSaveNo
  450. End If
  451.  
  452. End Sub
  453. '----------------------------------------------------------------
  454. '
  455. Private Function ThisFormSub() As Boolean
  456. Dim strName As String
  457. On Error Resume Next
  458.  
  459. strName = Me.Parent.Name
  460.  
  461. ThisFormSub = (Err.Number = 0)
  462.  
  463. Err.Clear
  464.  
  465. End Function
  466. '----------------------------------------------------------------
  467. '
  468. Private Sub ClickDate(ClickName As String)
  469. Dim Num As Long
  470.  
  471. Num = Mid(ClickName, Len("Day") + 1)
  472. CurYear = Year(DaysAndWeeks(Num))
  473. CurMonth = Month(DaysAndWeeks(Num))
  474. CurDay = Day(DaysAndWeeks(Num))
  475.  
  476. End Sub

C_Button



   

COPY

  1. Option Explicit
  2. '********************************************************************
  3.  
  4. Private WithEvents myButton As Access.CommandButton
  5. Private myParent As C_Controls
  6. Private myIndex As Long
  7. '--------------------------------------------------------------------
  8. '
  9. Public Property Set Item(ByRef Obj As Access.CommandButton)
  10.  
  11. Set myButton = Obj
  12.  
  13. End Property
  14. '--------------------------------------------------------------------
  15. '
  16. Public Property Get Item() As Access.CommandButton
  17.  
  18. Set Item = myButton
  19.  
  20. End Property
  21. '--------------------------------------------------------------------
  22. '
  23. Public Property Set Parent(ByRef Obj As C_Controls)
  24.  
  25. Set myParent = Obj
  26.  
  27. End Property
  28. '--------------------------------------------------------------------
  29. '
  30. Public Property Let Index(ByVal val As Long)
  31.  
  32. myIndex = val
  33.  
  34. End Property
  35. '--------------------------------------------------------------------
  36. '
  37. Public Property Get Index() As Long
  38.  
  39. Index = myIndex
  40.  
  41. End Property
  42. '--------------------------------------------------------------------
  43. '
  44. Public Property Get Self() As Object
  45.  
  46. Set Self = Me
  47.  
  48. End Property
  49. '--------------------------------------------------------------------
  50. '
  51. Public Sub DEL()
  52.  
  53. Set myButton = Nothing
  54. Set myParent = Nothing
  55.  
  56. End Sub
  57. '--------------------------------------------------------------------
  58. '
  59. Private Sub Class_Terminate()
  60.  
  61. Set myButton = Nothing
  62. Set myParent = Nothing
  63.  
  64. End Sub
  65. '--------------------------------------------------------------------
  66. '
  67. Private Sub myButton_Click()
  68.  
  69. Call myParent.onClick(myButton)
  70.  
  71. End Sub
  72. '--------------------------------------------------------------------
  73. '
  74. Private Sub myButton_DblClick(Cancel As Integer)
  75.  
  76. Call myParent.onDblClick(myButton, Cancel)
  77.  
  78. End Sub
  79. '--------------------------------------------------------------------
  80. '
  81. Private Sub myButton_KeyDown(KeyCode As Integer, Shift As Integer)
  82.  
  83. Call myParent.onKeyDown(myButton, KeyCode, Shift)
  84.  
  85. End Sub
  86. '--------------------------------------------------------------------
  87. '
  88. Private Sub myButton_MouseMove(Button As Integer, _
  89. Shift As Integer, _
  90. X As Single, _
  91. Y As Single)
  92.  
  93. Call myParent.onMouseMove(myButton, Button, Shift, X, Y)
  94.  
  95. End Sub

C_CheckBox



   

COPY

  1. Option Explicit
  2. '********************************************************************
  3.  
  4. Private WithEvents myCheckBox As Access.CheckBox
  5. Private myParent As C_Controls
  6. Private myIndex As Long
  7. '--------------------------------------------------------------------
  8. '
  9. Public Property Set Item(ByRef Obj As Access.CheckBox)
  10.  
  11. Set myCheckBox = Obj
  12.  
  13. End Property
  14. '--------------------------------------------------------------------
  15. '
  16. Public Property Get Item() As Access.CheckBox
  17.  
  18. Set Item = myCheckBox
  19.  
  20. End Property
  21. '--------------------------------------------------------------------
  22. '
  23. Public Property Set Parent(ByRef Obj As C_Controls)
  24.  
  25. Set myParent = Obj
  26.  
  27. End Property
  28. '--------------------------------------------------------------------
  29. '
  30. Public Property Let Index(ByVal val As Long)
  31.  
  32. myIndex = val
  33.  
  34. End Property
  35. '--------------------------------------------------------------------
  36. '
  37. Public Property Get Index() As Long
  38.  
  39. Index = myIndex
  40.  
  41. End Property
  42. '--------------------------------------------------------------------
  43. '
  44. Public Property Get Self() As Object
  45.  
  46. Set Self = Me
  47.  
  48. End Property
  49. '--------------------------------------------------------------------
  50. '
  51. Public Sub DEL()
  52.  
  53. Set myCheckBox = Nothing
  54. Set myParent = Nothing
  55.  
  56. End Sub
  57. '--------------------------------------------------------------------
  58. '
  59. Private Sub Class_Terminate()
  60.  
  61. Set myCheckBox = Nothing
  62. Set myParent = Nothing
  63.  
  64. End Sub
  65. '--------------------------------------------------------------------
  66. '
  67. Private Sub myCheckBox_Click()
  68.  
  69. Call myParent.onClick(myCheckBox)
  70.  
  71. End Sub
  72. '--------------------------------------------------------------------
  73. '
  74. Private Sub myCheckBox_DblClick(Cancel As Integer)
  75.  
  76. Call myParent.onDblClick(myCheckBox, Cancel)
  77.  
  78. End Sub
  79. '--------------------------------------------------------------------
  80. '
  81. Private Sub myCheckBox_MouseMove(Button As Integer, _
  82. Shift As Integer, _
  83. X As Single, _
  84. Y As Single)
  85.  
  86. Call myParent.onMouseMove(myCheckBox, Button, Shift, X, Y)
  87.  
  88. End Sub

C_ComboBox



   

COPY

  1. Option Explicit
  2. '********************************************************************
  3.  
  4. Private WithEvents myCheckBox As Access.CheckBox
  5. Private myParent As C_Controls
  6. Private myIndex As Long
  7. '--------------------------------------------------------------------
  8. '
  9. Public Property Set Item(ByRef Obj As Access.CheckBox)
  10.  
  11. Set myCheckBox = Obj
  12.  
  13. End Property
  14. '--------------------------------------------------------------------
  15. '
  16. Public Property Get Item() As Access.CheckBox
  17.  
  18. Set Item = myCheckBox
  19.  
  20. End Property
  21. '--------------------------------------------------------------------
  22. '
  23. Public Property Set Parent(ByRef Obj As C_Controls)
  24.  
  25. Set myParent = Obj
  26.  
  27. End Property
  28. '--------------------------------------------------------------------
  29. '
  30. Public Property Let Index(ByVal val As Long)
  31.  
  32. myIndex = val
  33.  
  34. End Property
  35. '--------------------------------------------------------------------
  36. '
  37. Public Property Get Index() As Long
  38.  
  39. Index = myIndex
  40.  
  41. End Property
  42. '--------------------------------------------------------------------
  43. '
  44. Public Property Get Self() As Object
  45.  
  46. Set Self = Me
  47.  
  48. End Property
  49. '--------------------------------------------------------------------
  50. '
  51. Public Sub DEL()
  52.  
  53. Set myCheckBox = Nothing
  54. Set myParent = Nothing
  55.  
  56. End Sub
  57. '--------------------------------------------------------------------
  58. '
  59. Private Sub Class_Terminate()
  60.  
  61. Set myCheckBox = Nothing
  62. Set myParent = Nothing
  63.  
  64. End Sub
  65. '--------------------------------------------------------------------
  66. '
  67. Private Sub myCheckBox_Click()
  68.  
  69. Call myParent.onClick(myCheckBox)
  70.  
  71. End Sub
  72. '--------------------------------------------------------------------
  73. '
  74. Private Sub myCheckBox_DblClick(Cancel As Integer)
  75.  
  76. Call myParent.onDblClick(myCheckBox, Cancel)
  77.  
  78. End Sub
  79. '--------------------------------------------------------------------
  80. '
  81. Private Sub myCheckBox_MouseMove(Button As Integer, _
  82. Shift As Integer, _
  83. X As Single, _
  84. Y As Single)
  85.  
  86. Call myParent.onMouseMove(myCheckBox, Button, Shift, X, Y)
  87.  
  88. End Sub

C_Controls



   

COPY

  1. Option Explicit
  2. '*******************************************************************
  3. Public Event Click(myCont As Object)
  4. Public Event Change(myCont As Object)
  5. Public Event DblClick(myCont As Object, _
  6. Cancel As Integer)
  7. Public Event MouseMove(myCont As Object, _
  8. Button As Integer, _
  9. Shift As Integer, _
  10. X As Single, _
  11. Y As Single)
  12. Public Event KeyPress(myCont As Object, _
  13. KeyAscii As Integer)
  14. Public Event KeyDown(myCont As Object, _
  15. KeyCode As Integer, _
  16. Shift As Integer)
  17. Private Labels As Dictionary
  18. Private TextBoxs As Dictionary
  19. Private CheckBoxs As Dictionary
  20. Private ComboBoxs As Dictionary
  21. Private Buttons As Dictionary
  22.  
  23. Private myParent As Object
  24. '*******************************************************************
  25. '
  26. Public Property Set Parent(ByRef Obj As Object)
  27.  
  28. Set myParent = Obj
  29.  
  30. End Property
  31. '*******************************************************************
  32. '
  33. Public Sub onClick(myCont As Object)
  34.  
  35. RaiseEvent Click(myCont)
  36.  
  37. End Sub
  38. '*******************************************************************
  39. '
  40. Public Sub onDblClick(myCont As Object, Cancel As Integer)
  41.  
  42. RaiseEvent DblClick(myCont, Cancel)
  43.  
  44. End Sub
  45. '*******************************************************************
  46. '
  47. Public Sub onMouseMove(myCont As Object, _
  48. Button As Integer, _
  49. Shift As Integer, _
  50. X As Single, _
  51. Y As Single)
  52.  
  53. RaiseEvent MouseMove(myCont, Button, Shift, X, Y)
  54.  
  55. End Sub
  56. '*******************************************************************
  57. '
  58. Public Sub onChange(myCont As Object)
  59.  
  60. RaiseEvent Change(myCont)
  61.  
  62. End Sub
  63. '*******************************************************************
  64. '
  65. Public Sub onKeyPress(myCont As Object, _
  66. KeyAscii As Integer)
  67.  
  68. RaiseEvent KeyPress(myCont, KeyAscii)
  69.  
  70. End Sub
  71. '--------------------------------------------------------------------
  72. '
  73. Public Sub onKeyDown(myCont As Object, _
  74. KeyCode As Integer, _
  75. Shift As Integer)
  76.  
  77. RaiseEvent KeyDown(myCont, KeyCode, Shift)
  78.  
  79. End Sub
  80. '*******************************************************************
  81. '
  82. Public Sub Init()
  83. Dim Ctrl As Control
  84. Dim Obj As Object
  85.  
  86. If myParent Is Nothing Then
  87. Exit Sub
  88. End If
  89.  
  90. Set Labels = New Dictionary
  91. Set TextBoxs = New Dictionary
  92. Set CheckBoxs = New Dictionary
  93. Set ComboBoxs = New Dictionary
  94. Set Buttons = New Dictionary
  95.  
  96. For Each Ctrl In myParent.Controls
  97. Select Case TypeName(Ctrl)
  98. Case "TextBox"
  99.  
  100. With New C_TextBox
  101. Set .Item = Ctrl
  102. Set .Parent = Me
  103. TextBoxs.Add Ctrl.Name, .Self
  104. End With
  105.  
  106. Case "Label"
  107. With New C_Label
  108. Set .Item = Ctrl
  109. Set .Parent = Me
  110. Labels.Add Ctrl.Name, .Self
  111. End With
  112.  
  113. Case "ComboBox"
  114.  
  115. With New C_ComboBox
  116. Set .Item = Ctrl
  117. Set .Parent = Me
  118. ComboBoxs.Add Ctrl.Name, .Self
  119. End With
  120.  
  121. Case "CheckBox"
  122.  
  123. With New C_CheckBox
  124. Set .Item = Ctrl
  125. Set .Parent = Me
  126. CheckBoxs.Add Ctrl.Name, .Self
  127. End With
  128.  
  129. Case "CommandButton"
  130.  
  131. With New C_Button
  132. Set .Item = Ctrl
  133. Set .Parent = Me
  134. Buttons.Add Ctrl.Name, .Self
  135. End With
  136.  
  137. End Select
  138. Next Ctrl
  139.  
  140. End Sub
  141. '*******************************************************************
  142. '
  143. Public Sub DEL()
  144. Dim Keys As Variant
  145.  
  146. For Each Keys In TextBoxs
  147. TextBoxs(Keys).DEL
  148. Next Keys
  149. Set TextBoxs = Nothing
  150.  
  151. For Each Keys In Labels
  152. Labels(Keys).DEL
  153. Next Keys
  154. Set Labels = Nothing
  155.  
  156. For Each Keys In ComboBoxs
  157. ComboBoxs(Keys).DEL
  158. Next Keys
  159. Set ComboBoxs = Nothing
  160.  
  161. For Each Keys In CheckBoxs
  162. CheckBoxs(Keys).DEL
  163. Next Keys
  164. Set CheckBoxs = Nothing
  165.  
  166. For Each Keys In Buttons
  167. Buttons(Keys).DEL
  168. Next Keys
  169. Set Buttons = Nothing
  170.  
  171. Set myParent = Nothing
  172.  
  173. End Sub

C_TextBox



   

COPY

  1. Option Explicit
  2. '********************************************************************
  3.  
  4. Private WithEvents myLabel As Access.Label
  5. Private myParent As C_Controls
  6. Private myIndex As Long
  7. '--------------------------------------------------------------------
  8. '
  9. Public Property Set Item(ByRef Obj As Access.Label)
  10.  
  11. Set myLabel = Obj
  12.  
  13. End Property
  14. '--------------------------------------------------------------------
  15. '
  16. Public Property Get Item() As Access.Label
  17.  
  18. Set Item = myLabel
  19.  
  20. End Property
  21. '--------------------------------------------------------------------
  22. '
  23. Public Property Set Parent(ByRef Obj As C_Controls)
  24.  
  25. Set myParent = Obj
  26.  
  27. End Property
  28. '--------------------------------------------------------------------
  29. '
  30. Public Property Let Index(ByVal val As Long)
  31.  
  32. myIndex = val
  33.  
  34. End Property
  35. '--------------------------------------------------------------------
  36. '
  37. Public Property Get Index() As Long
  38.  
  39. Index = myIndex
  40.  
  41. End Property
  42. '--------------------------------------------------------------------
  43. '
  44. Public Property Get Self() As Object
  45.  
  46. Set Self = Me
  47.  
  48. End Property
  49. '--------------------------------------------------------------------
  50. '
  51. Public Sub DEL()
  52.  
  53. Set myLabel = Nothing
  54. Set myParent = Nothing
  55.  
  56. End Sub
  57. '--------------------------------------------------------------------
  58. '
  59. Private Sub Class_Terminate()
  60.  
  61. Set myLabel = Nothing
  62. Set myParent = Nothing
  63.  
  64. End Sub
  65. '--------------------------------------------------------------------
  66. '
  67. Private Sub myLabel_Click()
  68.  
  69. Call myParent.onClick(myLabel)
  70.  
  71. End Sub
  72. '--------------------------------------------------------------------
  73. '
  74. Private Sub myLabel_DblClick(Cancel As Integer)
  75.  
  76. Call myParent.onDblClick(myLabel, Cancel)
  77.  
  78. End Sub
  79. '--------------------------------------------------------------------
  80. '
  81. Private Sub myLabel_MouseMove(Button As Integer, _
  82. Shift As Integer, _
  83. X As Single, _
  84. Y As Single)
  85.  
  86. Call myParent.onMouseMove(myLabel, Button, Shift, X, Y)
  87.  
  88. End Sub

C_TextBox



   

COPY

  1. Option Explicit
  2. '********************************************************************
  3.  
  4. Private WithEvents myTextBox As Access.TextBox
  5. Private myParent As C_Controls
  6. Private myIndex As Long
  7. '--------------------------------------------------------------------
  8. '
  9. Public Property Set Item(ByRef Obj As Access.TextBox)
  10.  
  11. Set myTextBox = Obj
  12.  
  13. End Property
  14. '--------------------------------------------------------------------
  15. '
  16. Public Property Get Item() As Access.TextBox
  17.  
  18. Set Item = myTextBox
  19.  
  20. End Property
  21. '--------------------------------------------------------------------
  22. '
  23. Public Property Set Parent(ByRef Obj As C_Controls)
  24.  
  25. Set myParent = Obj
  26.  
  27. End Property
  28. '--------------------------------------------------------------------
  29. '
  30. Public Property Let Index(ByVal val As Long)
  31.  
  32. myIndex = val
  33.  
  34. End Property
  35. '--------------------------------------------------------------------
  36. '
  37. Public Property Get Index() As Long
  38.  
  39. Index = myIndex
  40.  
  41. End Property
  42. '--------------------------------------------------------------------
  43. '
  44. Public Property Get Self() As Object
  45.  
  46. Set Self = Me
  47.  
  48. End Property
  49. '--------------------------------------------------------------------
  50. '
  51. Public Sub DEL()
  52.  
  53. Set myTextBox = Nothing
  54. Set myParent = Nothing
  55.  
  56. End Sub
  57. '--------------------------------------------------------------------
  58. '
  59. Private Sub Class_Terminate()
  60.  
  61. Set myTextBox = Nothing
  62. Set myParent = Nothing
  63.  
  64. End Sub
  65. '--------------------------------------------------------------------
  66. '
  67. Private Sub myTextBox_Change()
  68.  
  69. Call myParent.onChange(myTextBox)
  70.  
  71. End Sub
  72. '--------------------------------------------------------------------
  73. '
  74. Private Sub myTextBox_DblClick(Cancel As Integer)
  75.  
  76. Call myParent.onDblClick(myTextBox, Cancel)
  77.  
  78. End Sub
  79. '--------------------------------------------------------------------
  80. '
  81. Private Sub myTextBox_KeyPress(KeyAscii As Integer)
  82.  
  83. Call myParent.onKeyPress(myTextBox, KeyAscii)
  84.  
  85. End Sub
  86. '--------------------------------------------------------------------
  87. '
  88. Private Sub myTextBox_MouseMove(Button As Integer, _
  89. Shift As Integer, _
  90. X As Single, _
  91. Y As Single)
  92.  
  93. Call myParent.onMouseMove(myTextBox, Button, Shift, X, Y)
  94.  
  95. End Sub

C_Kyuzituクラス



   

COPY

  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Enum YobiType
  5. Shuku = 10
  6. Kokumin = 11
  7. Hurikae = 12
  8. Kanrei = 13
  9. End Enum
  10.  
  11. Private memShukuzitu As Dictionary
  12. Private memKokumin As Dictionary
  13. Private memHurikae As Dictionary
  14. Private memKanrei As Dictionary
  15. Private memYear As Long
  16. Private memMonth As Long
  17. Private memDay As Long
  18. Private memFormat As String
  19.  
  20. Public Property Let pYear(val As Long)
  21. Call KyuzituSet(val)
  22. End Property
  23.  
  24. Public Property Get pYear() As Long
  25. pYear = memYear
  26. End Property
  27.  
  28. Public Property Let SetStrDate(val As String)
  29.  
  30. If IsDate(val) Then
  31. Call KyuzituSet(CLng(DatePart("yyyy", val)))
  32. memMonth = CLng(DatePart("m", val))
  33. memDay = CLng(DatePart("d", val))
  34. Else
  35. Call KyuzituSet(1900)
  36. memMonth = 1
  37. memDay = 1
  38. End If
  39.  
  40. End Property
  41.  
  42. Public Property Let SetNumDate(val As Long)
  43.  
  44. Call KyuzituSet(Year(val))
  45. memMonth = Month(val)
  46. memDay = Day(val)
  47.  
  48. End Property
  49.  
  50. Public Property Let FormatFormat(val As String)
  51. memFormat = val
  52. End Property
  53.  
  54. Public Property Get GetStrDate() As String
  55. GetStrDate = Format(DateSerial(memYear, memMonth, memDay), memFormat)
  56. End Property
  57.  
  58. Public Property Get WeekNum() As Long
  59. WeekNum = Yobi
  60. End Property
  61.  
  62. Public Property Get DateNum() As Long
  63. DateNum = DateSerial(memYear, memMonth, memDay)
  64. End Property
  65.  
  66. Private Sub Class_Initialize()
  67.  
  68. Call KyuzituSet(Year(Date))
  69. memMonth = Month(Date)
  70. memDay = Day(Date)
  71.  
  72. End Sub
  73.  
  74. Private Sub Class_Terminate()
  75.  
  76. Set memShukuzitu = Nothing
  77. Set memKokumin = Nothing
  78. Set memHurikae = Nothing
  79. Set memKanrei = Nothing
  80.  
  81. End Sub
  82.  
  83. Private Function Yobi() As Long
  84.  
  85. If memShukuzitu.Exists(DateNum) Then
  86. Yobi = YobiType.Shuku
  87. Exit Function
  88. End If
  89.  
  90. If memKokumin.Exists(DateNum) Then
  91. Yobi = YobiType.Kokumin
  92. Exit Function
  93. End If
  94.  
  95. If memHurikae.Exists(DateNum) Then
  96. Yobi = YobiType.Kanrei
  97. Exit Function
  98. End If
  99.  
  100. If memKanrei.Exists(DateNum) Then
  101. Yobi = YobiType.Kanrei
  102. Exit Function
  103. End If
  104.  
  105. Yobi = Weekday(DateNum, vbSunday)
  106.  
  107. End Function
  108. '---------------------------------------
  109. Private Sub KyuzituSet(NewYear As Long)
  110.  
  111. If memYear <> NewYear Then
  112. memYear = NewYear
  113. Call makeShukuzitu
  114. Call makeKokumin
  115. Call makeHurikae
  116. Call makeKanrei
  117. End If
  118.  
  119. End Sub
  120. '---------------------------------------ロング値で与えられた日付の休日判定を行ないます。
  121. Private Sub makeShukuzitu()
  122. Dim iDay As Long
  123.  
  124. Set memShukuzitu = Nothing
  125. Set memShukuzitu = New Dictionary
  126.  
  127. '----------元日
  128. If DateSerial(memYear, 1, 1) > DateSerial(1948, 7, 19) Then
  129. memShukuzitu.Add DateSerial(memYear, 1, 1), "元旦"
  130. End If
  131.  
  132. '----------成人の日 1月15日 → 1月の第2月曜
  133. If memYear > 1949 And memYear < 2000 Then
  134. memShukuzitu.Add DateSerial(memYear, 1, 15), "成人の日"
  135. ElseIf memYear > 1999 Then
  136. memShukuzitu.Add DateSerial(memYear, 1, 14) - (Weekday(DateSerial(memYear, 1, 14), vbTuesday) Mod 7), "成人の日"
  137. End If
  138.  
  139. '----------建国記念の日
  140. If DateSerial(memYear, 2, 11) > DateSerial(1948, 7, 19) Then
  141. memShukuzitu.Add DateSerial(memYear, 2, 11), "建国記念の日"
  142. End If
  143.  
  144. '----------天皇誕生日
  145. If memYear > 2019 Then
  146. memShukuzitu.Add DateSerial(memYear, 2, 23), "天皇誕生日"
  147. End If
  148.  
  149. '----------春分の日
  150. 'int(19.8277+0.242194*(年-1980)-int((年-1983)/4)) ----------1851-1899年通用
  151. 'int(20.8357+0.242194*(年-1980)-int((年-1983)/4)) ----------1900-1979年通用
  152. 'int(20.8431+0.242194*(年-1980)-int((年-1980)/4)) ----------1980-2099年通用
  153. 'int(21.8510+0.242194*(年-1980)-int((年-1980)/4)) ----------2100-2150年通用
  154. Select Case memYear
  155. Case Is < 2100
  156. iDay = Int(20.8431 + 0.242194 * (memYear - 1980) - Int((memYear - 1980) / 4))
  157. Case Is >= 2100
  158. iDay = Int(20.851 + 0.242194 * (memYear - 1980) - Int((memYear - 1980) / 4))
  159. End Select
  160. If DateSerial(memYear, 3, iDay) > DateSerial(1948, 7, 19) Then
  161. memShukuzitu.Add DateSerial(memYear, 3, iDay), "春分の日"
  162. End If
  163.  
  164. '----------天皇誕生日→みどりの日→昭和の日
  165. If DateSerial(memYear, 4, 29) > DateSerial(1948, 7, 19) Then
  166. memShukuzitu.Add DateSerial(memYear, 4, 29), "昭和の日"
  167. End If
  168.  
  169. '----------即位の礼
  170. If memYear = 2019 Then
  171. memShukuzitu.Add DateSerial(memYear, 5, 1), "即位の礼"
  172. End If
  173.  
  174. '----------憲法記念日
  175. If DateSerial(memYear, 5, 3) > DateSerial(1948, 7, 19) Then
  176. memShukuzitu.Add DateSerial(memYear, 5, 3), "憲法記念日"
  177. End If
  178.  
  179. '----------みどりの日
  180. If memYear > 2006 Then
  181. memShukuzitu.Add DateSerial(memYear, 5, 4), "みどりの日"
  182. End If
  183.  
  184. '----------こどもの日
  185. If DateSerial(memYear, 5, 5) > DateSerial(1948, 7, 19) Then
  186. memShukuzitu.Add DateSerial(memYear, 5, 5), "こどもの日"
  187. End If
  188.  
  189. '----------海の日 7月20日 → 7月の第3月曜日
  190. If memYear > 1995 And memYear < 2003 Then
  191. memShukuzitu.Add DateSerial(memYear, 7, 20), "海の日"
  192. ElseIf memYear > 2002 Then
  193. If memYear = 2020 Then
  194. 'オリンピックイヤー
  195. memShukuzitu.Add DateSerial(memYear, 7, 23), "海の日"
  196. ElseIf memYear = 2021 Then
  197. 'オリンピックイヤー
  198. memShukuzitu.Add DateSerial(memYear, 7, 22), "海の日"
  199. Else
  200. memShukuzitu.Add DateSerial(memYear, 7, 21) - (Weekday(DateSerial(memYear, 7, 21), vbTuesday) Mod 7), "海の日"
  201. End If
  202. End If
  203.  
  204. '----------山の日"
  205. If memYear > 2015 Then
  206. If memYear = 2020 Then
  207. 'オリンピックイヤー
  208. memShukuzitu.Add DateSerial(memYear, 8, 10), "山の日"
  209. ElseIf memYear = 2021 Then
  210. 'オリンピックイヤー
  211. memShukuzitu.Add DateSerial(memYear, 8, 8), "山の日"
  212. Else
  213. memShukuzitu.Add DateSerial(memYear, 8, 11), "山の日"
  214. End If
  215. End If
  216.  
  217. '----------敬老の日 9月15日 → 9月の第3月曜日
  218. If memYear > 1965 And memYear < 2003 Then
  219. memShukuzitu.Add DateSerial(memYear, 9, 15), "敬老の日"
  220. ElseIf memYear > 2002 Then
  221. memShukuzitu.Add DateSerial(memYear, 9, 21) - (Weekday(DateSerial(memYear, 9, 21), vbTuesday) Mod 7), "敬老の日"
  222. End If
  223.  
  224. '----------秋分の日
  225. 'int(22.2588+0.242194*(年-1980)-int((年-1983)/4)) ----------1851-1899年通用
  226. 'int(23.2588+0.242194*(年-1980)-int((年-1983)/4)) ----------1900-1979年通用
  227. 'int(23.2488+0.242194*(年-1980)-int((年-1980)/4)) ----------1980-2099年通用
  228. 'int(24.2488+0.242194*(年-1980)-int((年-1980)/4)) ----------2100-2150年通用
  229. Select Case memYear
  230. Case Is < 2100
  231. iDay = Int(23.2488 + 0.242194 * (memYear - 1980) - Int((memYear - 1980) / 4))
  232. Case Is >= 2100
  233. iDay = Int(24.2488 + 0.242194 * (memYear - 1980) - Int((memYear - 1980) / 4))
  234. End Select
  235. If DateSerial(memYear, 9, iDay) > DateSerial(1948, 7, 19) Then
  236. memShukuzitu.Add DateSerial(memYear, 9, iDay), "秋分の日"
  237. End If
  238.  
  239. '----------体育の日 → スポーツの日 10月10日 → 10月の第二月曜日
  240. If memYear > 1965 And memYear < 2000 Then
  241. memShukuzitu.Add DateSerial(memYear, 10, 10), "体育の日"
  242. ElseIf memYear > 1999 Then
  243. If memYear = 2020 Then
  244. 'オリンピックイヤー
  245. memShukuzitu.Add DateSerial(memYear, 7, 24), "スポーツの日"
  246. ElseIf memYear = 2021 Then
  247. 'オリンピックイヤー
  248. memShukuzitu.Add DateSerial(memYear, 7, 23), "スポーツの日"
  249. Else
  250. memShukuzitu.Add DateSerial(memYear, 10, 14) - (Weekday(DateSerial(memYear, 10, 14), vbTuesday) Mod 7), "スポーツの日"
  251. End If
  252. End If
  253.  
  254. '----------即位礼正殿の儀
  255. If memYear = 2019 Then
  256. memShukuzitu.Add DateSerial(memYear, 10, 22), "即位礼正殿の儀"
  257. End If
  258.  
  259. '----------文化の日
  260. If DateSerial(memYear, 11, 3) > DateSerial(1948, 7, 19) Then
  261. memShukuzitu.Add DateSerial(memYear, 11, 3), "文化の日"
  262. End If
  263.  
  264. '----------勤労感謝の日
  265. If DateSerial(memYear, 11, 23) > DateSerial(1948, 7, 19) Then
  266. memShukuzitu.Add DateSerial(memYear, 11, 23), "勤労感謝の日"
  267. End If
  268.  
  269. '----------天皇誕生日
  270. If memYear > 1988 And memYear < 2019 Then
  271. memShukuzitu.Add DateSerial(memYear, 12, 23), "天皇誕生日"
  272. End If
  273.  
  274. End Sub
  275.  
  276. Private Sub makeKokumin()
  277. Dim D() As Long
  278. Dim Keys As Variant
  279. Dim iCount As Long
  280. Dim I As Long
  281. Dim J As Long
  282. Dim Target As Long
  283.  
  284. If memShukuzitu.Count = 0 Then
  285. Exit Sub
  286. End If
  287.  
  288. If memYear < 1988 Then
  289. Exit Sub
  290. End If
  291.  
  292. Set memKokumin = Nothing
  293. Set memKokumin = New Dictionary
  294.  
  295. '-------------------------------国民の休日の判定
  296. ReDim D(memShukuzitu.Count - 1)
  297. For Each Keys In memShukuzitu
  298. D(iCount) = Keys
  299. iCount = iCount + 1
  300. Next
  301.  
  302. For I = 0 To UBound(D)
  303. For J = 0 To UBound(D)
  304. '-----------------------該当の組み合わせがある場合
  305. If D(J) - D(I) = 2 Then
  306. Target = (D(J) + D(I)) / 2
  307. If Not memShukuzitu.Exists(Target) Then
  308. memKokumin.Add Target, "休日"
  309. End If
  310. End If
  311. Next J
  312. Next I
  313.  
  314. End Sub
  315.  
  316. Private Sub makeHurikae()
  317. Dim iDay As Long
  318. Dim fDay As Long
  319. Dim boHurikae As Boolean
  320.  
  321. If memShukuzitu.Count = 0 Then
  322. Exit Sub
  323. End If
  324.  
  325. If memYear < 1973 Then
  326. Exit Sub
  327. End If
  328.  
  329. Set memHurikae = Nothing
  330. Set memHurikae = New Dictionary
  331.  
  332. For iDay = DateSerial(memYear, 1, 1) To DateSerial(memYear, 12, 31)
  333. '---------------------------日曜日であること
  334. If Weekday(iDay) = 1 Then
  335. '-------------------祝日であること
  336. If memShukuzitu.Exists(iDay) Then
  337. boHurikae = True
  338. fDay = iDay
  339. End If
  340. End If
  341.  
  342. '---------------------------フラッグを立てた後、最初の祝日でない日を振替日とする
  343. If boHurikae = True Then
  344. If iDay > fDay Then
  345. '-------------------祝休日に該当しない場合、振替日にする
  346. If Not memShukuzitu.Exists(iDay) Then
  347. memHurikae.Add iDay, "振替"
  348. boHurikae = False
  349. End If
  350. End If
  351. End If
  352.  
  353. Next iDay
  354.  
  355. End Sub
  356.  
  357. Private Sub makeKanrei()
  358.  
  359. Set memKanrei = Nothing
  360. Set memKanrei = New Dictionary
  361.  
  362. '-----------------------------------慣例になっている休日
  363. With memKanrei
  364. .Add DateSerial(memYear, 1, 1), "慣例"
  365. .Add DateSerial(memYear, 1, 2), "慣例"
  366. .Add DateSerial(memYear, 1, 3), "慣例"
  367. .Add DateSerial(memYear, 12, 31), "慣例"
  368. End With
  369.  
  370. End Sub