BIRTHDAY DATE (strategy)

User avatar
sal21
PlatinumLounger
Posts: 3559
Joined: 26 Apr 2010, 17:36

BIRTHDAY DATE (strategy)

Post by sal21 »

what is the correct method to fill the three combobox to set a birtday date?


note:
in mind... for the birthday, consider only if the customer have >= 18 year old based current date
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 71177
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: BIRTHDAY DATE (strategy)

Post by HansV »

Wouldn't it be easier to let the user enter their birthdate?
Regards,
Hans

User avatar
sal21
PlatinumLounger
Posts: 3559
Joined: 26 Apr 2010, 17:36

Re: BIRTHDAY DATE (strategy)

Post by sal21 »

HansV wrote:
06 May 2021, 12:17
Wouldn't it be easier to let the user enter their birthdate?
good suggestion.
but possible to check with a button the correct date, for example:

1) <18 year old
2) 31/02/2021

User avatar
HansV
Administrator
Posts: 71177
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: BIRTHDAY DATE (strategy)

Post by HansV »

For example:

Code: Select all

    If Not IsDate(Me.txtBirthDate) Then
        MsgBox "Date not valid!"
        Exit Sub
    End If
    If Age(Me.,txtBirthDate) < 18 Then
        MsgBox "Age under 18!"
        Exit Sub
    End If
This uses the following function:

Code: Select all

Public Function Age(BirthDate) As Long
    Dim y As Long
    Dim m As Long
    Dim d As Long
    m = DateDiff("m", BirthDate, Date)
    d = DateDiff("d", DateAdd("m", m, BirthDate), Date)
    If d < 0 Then
        m = m - 1
    End If
    Age = m \ 12
End Function
Regards,
Hans

User avatar
sal21
PlatinumLounger
Posts: 3559
Joined: 26 Apr 2010, 17:36

Re: BIRTHDAY DATE (strategy)

Post by sal21 »

HansV wrote:
06 May 2021, 14:36
For example:

Code: Select all

    If Not IsDate(Me.txtBirthDate) Then
        MsgBox "Date not valid!"
        Exit Sub
    End If
    If Age(Me.,txtBirthDate) < 18 Then
        MsgBox "Age under 18!"
        Exit Sub
    End If
This uses the following function:

Code: Select all

Public Function Age(BirthDate) As Long
    Dim y As Long
    Dim m As Long
    Dim d As Long
    m = DateDiff("m", BirthDate, Date)
    d = DateDiff("d", DateAdd("m", m, BirthDate), Date)
    If d < 0 Then
        m = m - 1
    End If
    Age = m \ 12
End Function
HUMMM..
Now with your suggetion, i use textbox.
possible to insert in text box this format string: __/__/____

User avatar
HansV
Administrator
Posts: 71177
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: BIRTHDAY DATE (strategy)

Post by HansV »

You might use the Masked Edit Control with the Mask property set to ##/##/####
Regards,
Hans

User avatar
sal21
PlatinumLounger
Posts: 3559
Joined: 26 Apr 2010, 17:36

Re: BIRTHDAY DATE (strategy)

Post by sal21 »

HansV wrote:
06 May 2021, 16:16
You might use the Masked Edit Control with the Mask property set to ##/##/####
GOOD.