กระทู้เก่าบอร์ด อ.Yeadram
2,609 2
URL.หัวข้อ /
URL
code คำนวณอายุของ access ค่ะ
ต้องการให้ฐานข้อมูลที่มีอยู่ แสดงอายุของประชากรเป็น ปี เดือน วัน ค่ะ ทำอย่างไรคะ
2 Reply in this Topic. Dispaly 1 pages and you are on page number 1
1 @R04166
format(a,"yyyy mmmm dd")
2 @R04187
สร้างหน้า Form ตามรูป พร้อมกำหนดชื่อ Txtbox
ผูกโด้ด VBA
Private Sub Command10_Click()
On Error GoTo Err_Command10_Click
Dim DayRange As Single
Dim MonthRange As Single
Dim YearRange As Single
YearRange = Year(CurrentDate) - Year(StartDate)
MonthRange = Month(CurrentDate) - Month(StartDate)
DayRange = Day(CurrentDate) - Day(StartDate)
If CurrentDate < StartDate Then
MsgBox "CurrentDate is less than StartDate", vbOKOnly
Exit Sub
End If
If MonthRange < 0 Then
YearRange = YearRange - 1
MonthRange = 12 - Month(StartDate) + Month(CurrentDate)
End If
If DayRange < 0 Then
If MonthRange > 0 Then
MonthRange = MonthRange - 1
Else
YearRange = YearRange - 1
MonthRange = 11
End If
DayRange = 31 - Day(StartDate) + Day(CurrentDate)
Select Case Month(StartDate)
Case 4, 6, 9, 11
DayRange = DayRange - 1
Case 2
DayRange = DayRange - 3
End Select
End If
Years = YearRange
Months = MonthRange
Days = DayRange
Exit_Command10_Click:
Exit Sub
Err_Command10_Click:
MsgBox Err.Description
Resume Exit_Command10_Click
End Sub
ผูกโด้ด VBA
Private Sub Command10_Click()
On Error GoTo Err_Command10_Click
Dim DayRange As Single
Dim MonthRange As Single
Dim YearRange As Single
YearRange = Year(CurrentDate) - Year(StartDate)
MonthRange = Month(CurrentDate) - Month(StartDate)
DayRange = Day(CurrentDate) - Day(StartDate)
If CurrentDate < StartDate Then
MsgBox "CurrentDate is less than StartDate", vbOKOnly
Exit Sub
End If
If MonthRange < 0 Then
YearRange = YearRange - 1
MonthRange = 12 - Month(StartDate) + Month(CurrentDate)
End If
If DayRange < 0 Then
If MonthRange > 0 Then
MonthRange = MonthRange - 1
Else
YearRange = YearRange - 1
MonthRange = 11
End If
DayRange = 31 - Day(StartDate) + Day(CurrentDate)
Select Case Month(StartDate)
Case 4, 6, 9, 11
DayRange = DayRange - 1
Case 2
DayRange = DayRange - 3
End Select
End If
Years = YearRange
Months = MonthRange
Days = DayRange
Exit_Command10_Click:
Exit Sub
Err_Command10_Click:
MsgBox Err.Description
Resume Exit_Command10_Click
End Sub
Time: 0.3671s