Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2004
    Posts
    13

    Unanswered: Hide an object if a date doesn't match today's date

    I have a form that shows the name, birthdate and age of a person (using text boxes). This info comes from a table. What I want is for this information to NOT show unless the birthdate matches the current date. I have the current date displaying also...


  2. #2
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Suppose you show the current date in a textbox called currDate, and the birthday is shown in another called txtBirthday, then in the OnCurrent event put the next comparison

    PHP Code:
    if currDate txtBirthday then
      ThatObject
    .Visible=False
    Else
      
    ThatObject.Visible=True
    End 
    If 

  3. #3
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    But if you do so, you will only show babys who are boren on the current date.

  4. #4
    Join Date
    Jan 2005
    Posts
    144
    + i beleive he wanted to display the controls when the current date matched the stored birthdate for that particular person. in this case, the logic of the code is backwards and should actually be:

    Code:
    if currDate = txtBirthday then 
      ThatObject.Visible=True 
    Else 
      ThatObject.Visible=False 
    End If
    + i agree 100% that this code (in it's corrected form) will work. might i suggest though that if you're not using the control that contains the current date for any other purpose, that you remove it entirely? i think it's a bit unnecessary and even somewhat redundant to display another control when you can accomplish the same task with the following code:

    Code:
    if txtBirthday=Date() then 
      ThatObject.Visible=True
    Else 
      ThatObject.Visible=False
    End If
    + this is just my personal opinion, but take it for what it's worth. and of course, either of these bits of code would work if placed in the OnCurrent event of your form.

    regards - [daVinci] ҿ

  5. #5
    Join Date
    Jan 2004
    Location
    Aberdeen, Scotland
    Posts
    1,067
    I think what your actually after is to check the day and month of the 2 dates to see if they match hence checking Birthday

    i.e.
    Code:
    If Day(Now()) = Day(txtBirthdate) AND Month(Now()) = Month(txtBirthdate) Then
    unless you just want new babies born in this specific day
    Last edited by DavidCoutts; 01-10-05 at 07:05. Reason: Missing Brackets

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Agree with David
    Also yoiu should place the code as a function in the following events

    forms "oncurrent" - to set when you navigate through the recordset

    forms "afterupdate" - to set after updating
    and optionally
    controls "lostfocus" event to set the display after datacapture

    the setting can then be
    mycontrol.visible = udfTestforBirthday([DateofBirth])

    private function udfTestforBirthday(varDateBorn as variant) as boolean
    if len(varDateborn)=0 then
    udfTestforBirthday=false
    elseif not isdate(varDateborn) then
    udfTestforBirthday=false
    elseIf Day(Now()) = Day(varDateborn) AND Month(Now()) = Month(varDateborn) Then
    udfTestforBirthday=true
    else
    udfTestforBirthday=false
    endif
    end function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •