การหาคนที่เกิดในช่วง
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 258   1
URL.หัวข้อ / URL
การหาคนที่เกิดในช่วง

ผมได้ตอบคำถามในการหาคนที่เกิดในช่วง 1 เดือนข้างหน้ามีใครบ้าง โดยหาจากวันเกิด ผมได้ตอบไว้ที่
http://www.helptalk.net/forums/access/messages/98075.html
ดังนี้

Function ComingBirthDay(ComingDate As Date) As String
' This function is to find who will have a birthday in the next period of one month
' starting from from today, Now().
' Today does not have to be the 1st of this month, any day in this month
' ComingDate is a birthday

Dim FromDate As Date, ToDate As Date
Dim FromMonth As Integer, FromDay As Integer
Dim ToMonth As Integer, ToDay As Integer

FromDate = Now()
FromMonth = Format(FromDate, "M")
FromDay = Format(FromDate, "D")

ToDate = DateAdd("m", 1, Now())
ToMonth = Format(ToDate, "M")
ToDay = Format(ToDate, "D")

If Format(Now(), "M") < 12 Then
If Format(ComingDate, "M") >= FromMonth And Format(ComingDate, "M") <= ToMonth Then
If Format(ComingDate, "M") < ToMonth And Format(ComingDate, "D") >= FromDay Then
ComingBirthDay = "Yes"
ElseIf Format(ComingDate, "M") > FromMonth And Format(ComingDate, "D") <= FromDay Then
ComingBirthDay = "Yes"
Else
ComingBirthDay = "No"
End If
Else
ComingBirthDay = "No"
End If
Else
If Format(ComingDate, "M") = 12 And ToMonth = 12 Then
If Format(ComingDate, "D") >= FromDay Then
ComingBirthDay = "Yes"
Else
ComingBirthDay = "NO"
End If
ElseIf Format(ComingDate, "M") = 12 And ToMonth = 1 Then
If Format(ComingDate, "D") >= FromDay Then
ComingBirthDay = "Yes"
Else
ComingBirthDay = "NO"
End If
ElseIf Format(ComingDate, "M") = 1 And ToMonth = 1 Then
If Format(ComingDate, "D") <= ToDay Then
ComingBirthDay = "Yes"
Else
ComingBirthDay = "NO"
End If
Else
ComingBirthDay = "NO"
End If
End If

'Debug.Print FromDay; FromMonth
'Debug.Print ToDay; ToMonth
'Debug.Print Format(ComingDate, "d") & "/" & Format(ComingDate, "m")

End Function

ลองศึกษาโค้ด และถ้าหากเจอบัก กรุณาช่วยแจ้งมาด้วยนะครับ
*** Edited by Supap Chaiya *** 24/3/2546 11:18:36

1 Reply in this Topic. Dispaly 1 pages and you are on page number 1

1 @R06903
   
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0610s