Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display Happy Birthday on Form

Status
Not open for further replies.

jeffshex

Technical User
Jun 30, 2005
208
US
Here's a little piece of code that looks for the date of birth (DOB) on the form and displays a label saying Happy Birthday if it is, otherwise hides it if not.
Feel free to modify - I just find it neat.

Code:
Private Sub Form_Current()
Dim dteBD As Date
Dim dteToday As Date

Me.lblHappyBDay.Visible = False
If IsNull(Me.DOB) Then
    Cancel = True
    Exit Sub
Else
    dteBD = Format(Me.DOB, "m/d")
    dteToday = Format(Date, "m/d")
    If dteBD = dteToday Then
        Me.lblHappyBDay.Visible = True
    Else
        Cancel = True
        Exit Sub
    End If
End If

End Sub
 



Hi,

You have declared dteBD & dteToday As Date, yet you assign STRINGS to each using the Format function???

Rather ...
Code:
    If Format(Me.DOB, "m/d") = Format(Date, "m/d") Then
        Me.lblHappyBDay.Visible = True
  ...


Skip,

[glasses]I'll be dressed to the nines this week, as I go to have my prostatectomy...
Because, if I'm gonna BE impotent, I want to LOOK impotent![tongue]
 

Code:
Private Sub Form_Current()
Me.lblHappyBDay.Visible = False
If Not IsNull(Me.DOB) Then
  If Format(Me.DOB, "mmdd") = Format(Date, "mmdd") Then
    Me.lblHappyBDay.Visible = True
  End If
End If
End Sub

BTW, Cancel is not available in this event. On events where it is, you'll see this

Private Sub EventName(Cancel as Integer)


The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
A one line way:
Private Sub Form_Current()
Me!lblHappyBDay.Visible = (Format(Me!DOB, "mmdd") = Format(Date, "mmdd"))
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top