none
Access current record in detail section RRS feed

  • Question

  • Hello,

    I have problems to reference fields from the current record in the detail section.

    What I basically want to do in the detail section: The user should enter the age of a person in an unbound text field. The change event should then convert the age into a date information and store the date in the database (birthdate) instead of the entered age.

    The unbound age field should always display the current age: DateDiff("yyyy", Date, birthdate).

    Therefore I did the following:

    Private Sub Detail_Paint()
    
    Age = DateDiff("yyyy", Date, birthdate)
    
    End Sub

    Unfortunately it doesn't work, because everything starts to flicker and the age is not shown.

    Any ideas?



    Monday, August 24, 2015 8:41 AM

Answers

  • It sounds like you are using a continuous or datasheet form. That was not indicated in your post. The method you are trying to use will only work in single form view. As you see, an unbound textbox is the same for all rows.

    You would need to put the unbound textbox in the header section. In the detail section, you can add a textbox with it's controlsource set to your age formula.

    Monday, August 24, 2015 2:44 PM

All replies

  • Your Age formula should be in the oncurrent of the form, not paint.

    The reverse formula should be in the afterupdate event of the Age textbox.

    Monday, August 24, 2015 12:27 PM
  • You do realize that the birthdate will never be accurate in this type of setup?  Are you not able to acquire the person's actual date of birth and enter it, rather than the age? 

    You state that you want the unbound text box to display the age always.  This may present problems if you are also using it update data as an unbound control.

    Monday, August 24, 2015 2:19 PM
  • Yes I am aware of this restriction (it's a customer requirement).

    @Alphonse G: When I put the age formula into the oncurrent event of the form, it doesn't reference each text box in the detail section correctly. Instead it just takes the value from the first record and applys the result to all other text boxes in the detail section.

    Monday, August 24, 2015 2:35 PM
  • It sounds like you are using a continuous or datasheet form. That was not indicated in your post. The method you are trying to use will only work in single form view. As you see, an unbound textbox is the same for all rows.

    You would need to put the unbound textbox in the header section. In the detail section, you can add a textbox with it's controlsource set to your age formula.

    Monday, August 24, 2015 2:44 PM