x
Solved

# Show / Hide image if current day/month equals birthday

Posted on 2016-08-14
Medium Priority
80 Views
Dear Experts,

Okay...a little stumped on this one.

I want to show an image of a birthday cake (imgCake) only if the date in the student's birthday field (me.studentDOB) is equal to today's month and day.

Any ideas on vba syntax?

Thanks!
0
Question by:shogun5
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 58

Assisted Solution

Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 41755525
In the on current event:

If Month(Now()) = Month([Birthdate]) and Day(Now()) = Day([Birthdate]) then
Me.<myimagecontrolname>.Visible = True
Else
Me.<myimagecontrolname>.Visible = False
End If

What the above does not take into account is leap years and someone born on 2/29.  Not sure how you want to handle that.  Some say on non-lean years, the birthday occurs on the 28th, others 3/1.

Jim.
0

LVL 52

Accepted Solution

Gustav Brock earned 1000 total points
ID: 41755572
You can use the function below and this expression:

Me!imgCake.Visible = IsBirthday(Me!studentDOB.Value)

``````Public Function IsBirthday( _
ByVal datDateOfBirth As Date, _
Optional varDate As Variant) _
As Boolean

' Returns True if date varDate (or today) is an annual birthday.
' Validates correctly Feb. 29. as Feb. 28. for non leap years and
' excludes annual birthdays earlier than the date of birth.
'
' Gustav Brock, Cactus Data ApS.
' 2000-12-20.
' 2008-05-12. Converted to stand-alone function.

Dim datDate     As Date
Dim booBirthday As Boolean

' No special error handling.
On Error Resume Next

If IsDate(varDate) Then
datDate = Fix(CDate(varDate))
Else
datDate = Date
End If
booBirthday = (DateDiff("d", datDate, DateAdd("yyyy", Abs(DateDiff("yyyy", datDateOfBirth, datDate)), datDateOfBirth)) = 0)

IsBirthday = booBirthday

End Function
``````
/gustav
0

LVL 31

Assisted Solution

hnasr earned 500 total points
ID: 41755621
Some variation from above:

Check this to flag a date if
equal months) AND   equal days
OR
28 days for Feb if birth was in a leap year.
Assume: date of birth (dob), and current date (dn)

``````Me.imageControl.Visible = ((month(dn)=month(dob)) AND ((Day(dn)=Day(dob)) OR ( Month(dob=2) AND (Day(dn) Mod 28)=(Day(dob) Mod 29) )))
``````
0

Author Closing Comment

ID: 41755689
Thank you!
0

LVL 52

Expert Comment

ID: 41755946
You are welcome!

/gustav
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
###### Suggested Courses
Course of the Month15 days, 7 hours left to enroll