Solved

Show / Hide image if current day/month equals birthday

Posted on 2016-08-14
5
72 Views
Last Modified: 2016-08-14
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
Comment
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
  • Learn & ask questions
5 Comments
 
LVL 58

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 125 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 50

Accepted Solution

by:
Gustav Brock earned 250 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

Open in new window

/gustav
0
 
LVL 30

Assisted Solution

by:hnasr
hnasr earned 125 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) )))

Open in new window

0
 

Author Closing Comment

by:shogun5
ID: 41755689
Thank you!
0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 41755946
You are welcome!

/gustav
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question