Results 1 to 4 of 4
  1. #1
    4 Star Lounger
    Join Date
    May 2003
    Location
    Austin
    Posts
    401
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Pull date from table for form (Access 2003)

    I'd like to populate a label or text box or form caption with the date value from it's table. How can this be done?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Pull date from table for form (Access 2003)

    I assume that the date field is part of the record source of the form.

    The easiest way is to place a text box on the form and set its Control Source property to the name of the field (you can select the field name from the dropdown list). (If you wish, you can set the Locked property of the text box to Yes and the Enabled property to No so that the user can't edit the date.)

    If you prefer a label: place a label on the form and name it lblDate.
    Create an event procedure for the On Current event of the form:

    Private Sub Form_Current()
    Me.lblDate.Caption = Me.DateField
    End Sub

    where DateField is the name of the date field.

    If you want to set the caption of the form itself:

    Private Sub Form_Current()
    Me.Caption = Me.DateField
    End Sub

  3. #3
    4 Star Lounger
    Join Date
    May 2003
    Location
    Austin
    Posts
    401
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Pull date from table for form (Access 2003)

    Not really. It's just a table property. DateCreated or DateModified are the only attributes I've seen in code, but accessing it has been quite a pain.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Pull date from table for form (Access 2003)

    You could use the On Load or On Open event of the form, for example:

    Private Sub Form_Load()
    Me.Caption = CurrentData.AllTables(Me.RecordSource).DateCreated
    End Sub

    or if you want to specify a format:

    Private Sub Form_Load()
    Me.Caption = Format(CurrentData.AllTables(Me.RecordSource).Date Created, "Short Date")
    End Sub

Posting Permissions

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