Date of birth in "Dutch" format ddmmyyyy in userform and

Alfx3

New Member
Joined
Apr 2, 2017
Messages
2
As a newbe, I tried to receive the date of birth from a form in a local format: ddmmyyyy.
somewhere I messed up, but couldn't find a correct solution.
Can anybody tell me where I'm wrong and how to correct? Here's my code sofar:

Private Sub dtpGeboorteDatum_Exit(ByVal cancel As MSForms.ReturnBoolean)

If Left(dtpGeboorteDatum.Value, 2) > 31 Or Mid(dtpGeboorteDatum.Value, 3, 2) > 12 Then
MsgBox "Incorrect dat: please enter as ddmmjjjj", vbCritical​
dtpGeboorteDatum.Value = vbNullString​
dtpGeboorteDatum.SetFocus​
GoTo formulier​
Else


dDate = DateSerial(Year(Date), Month(Date), Day(Date))
If Not dDate Like "########" Or Len(dDate) <> 8 Then
MsgBox "Incorrect dat: please enter as ddmmjjj"​
dtpGeboorteDatum.SetFocus​
GoTo formulier​
End If
dDate = Mid(dDate, 5, 4) & "/" & Mid(dDate, 3, 2) & "/" & Left(dDate, 2)

If dDate <> dtpGeboorteDatum.Value Then dtpGeboorteDatum.Value = dDate
End If
formulier:
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Maybe ...

Code:
Private Sub dtpGeboorteDatum_Exit(ByVal cancel As MSForms.ReturnBoolean)
  Dim sDate         As String
  Dim dDate         As Date
  Dim iDy           As Long
  Dim iMo           As Long
  Dim iYr           As Long

  sDate = dtpGeboorteDatum.Value

  If sDate Like "########" Then
    iDy = Left(sDate, 2)
    iMo = Mid(sDate, 3, 2)
    iYr = Mid(sDate, 5, 4)

    On Error GoTo Oops
    dDate = DateSerial(iYr, iMo, iDy)
    If iDy <> Day(dDate) Or iMo <> Month(dDate) Or iYr <> Year(dDate) Then GoTo Oops
    ' it's good; do whatever
    Exit Sub
  End If

Oops:
  MsgBox "Incorrect date: please enter as ddmmjjjj", vbCritical
  dtpGeboorteDatum.Value = vbNullString
  dtpGeboorteDatum.SetFocus
End Sub
 
Last edited:
Upvote 0
Brilliant!just copy-paste and run..... and it works perfect
thanks a lot!
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,215,686
Messages
6,126,202
Members
449,298
Latest member
Jest

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top