[AccessD] Birthday in table

Lembit Soobik lembit.dbamail at t-online.de
Mon Jun 18 07:30:36 CDT 2007


Now, what I have made out of it is here:
- I did not like the year 2000 as default, so I changed it to 1004 to be 
distinguishable from actual birthay in 2000.
- I added a separate field for birth year
- the birth year field is placed over the birth year of the birthday field, 
so in case no year is given, the year is not shown.
- when a year is entered in either field, it is inserted int both fields, so 
whichever field has the focus, the display is the same if a year was given.

for information, here is the code:
'=============Begin Code

Private Sub txtGeburtsjahr_AfterUpdate()
    On Error GoTo Error_txtGeburtsjahr_AfterUpdate
    If Nz(Me.txtGeburtsjahr, 0) < 1004 Then
        Me.txtGeburtstag = Day(Me.txtGeburtstag) _
        & "." & Month(Me.txtGeburtstag) & "." & 1004
        Me.txtGeburtsjahr = ""
    Else
        Me.txtGeburtstag = Day(Me.txtGeburtstag) _
        & "." & Month(Me.txtGeburtstag) & "." & Me.Geburtsjahr
    End If
Exit_txtGeburtsjahr_AfterUpdate:
    Exit Sub
Error_txtGeburtsjahr_AfterUpdate:
    MsgBox "Das Datum ist ungültig: " & Day(Me.txtGeburtstag) _
    & "." & Month(Me.txtGeburtstag) & "." & Me.Geburtsjahr
    Me.Geburtsjahr = ""
    Resume Exit_txtGeburtsjahr_AfterUpdate
End Sub

'================================
Private Sub txtGeburtstag_AfterUpdate()
    If IsNull(Me.txtGeburtstag) = True Then
        Me.txtGeburtsjahr = ""
    ElseIf Year(Me.txtGeburtstag) <= 1004 Then
        Me.txtGeburtsjahr = ""
        Me.txtGeburtstag = Day(Me.txtGeburtstag) _
        & "." & Month(Me.txtGeburtstag) & "." & 1004
    End If
    Form_Current
End Sub
'-----------------------------------------------------------

Private Sub txtGeburtstag_Click()
    If Me.txtGeburtstag > #1/1/1004# Then
    Else
        Me.txtGeburtstag.SelStart = 0
        Me.txtGeburtstag.SelLength = 0
    End If
End Sub
'-----------------------------------------------------------

Private Sub txtGeburtstag_Enter()
    Me.txtGeburtstag.SelStart = 0
    Me.txtGeburtstag.SelLength = 0
End Sub
'-----------------------------------------------------------

Private Sub Form_Current()
    If Me.txtGeburtstag >= #1/1/1004# Then
        ' Set Default Format
        Me.txtGeburtstag.InputMask = ""
        If Me.txtGeburtstag > #1/1/1900# Then
            Me.txtGeburtsjahr = Format(Me.txtGeburtstag, "yyyy")
            Me.txtGeburtstag.Format = "dd.mm.yyyy"
        Else
        End If
    Else
        ' Set Custom Mask With Preset Year 1004
        Me.txtGeburtstag.Format = ""
        Me.txtGeburtstag.InputMask = "99.99.\1\0\0\4;0;_"
    End If

    If Me.NewRecord Then
        Me.txtGeburtstag.SetFocus
    End If   ' Me.NewRecord
End Sub
'================================

'=============End Code

Lembit 




More information about the AccessD mailing list