Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    May 2002
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Auto Date Entry (Access 2002)

    In a Table; one field has a date and the next field must have a date that would automatically be entered as 30 days from the first field date. How can this be accomplished without going to a form? Thanks in advance for any info.

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

    Re: Auto Date Entry (Access 2002)

    a) If the second date is always 30 days from the first date, why store it in the table?
    [img]/forums/images/smilies/cool.gif[/img] Why do you want to avoid the use of a form? You should never let users enter data directly into a table or query.

    (In a form, you could use the After Update event of the control bound to the first date, to set the second date.)

  3. #3
    2 Star Lounger
    Join Date
    May 2002
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Auto Date Entry (Access 2002)

    Thanks Han. I just wondered if it could be stored in a table and why would the use want to (this was a question asked of me). Secondly, could you be more specific about the After Undate procedure; I haven't used that yet. Thanks much.

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

    Re: Auto Date Entry (Access 2002)

    If you create a form based on the table, you will have a text box bound to the first date field, i.e. a text box whose Control Source property is the name of the first date field. Let's say that this text box is named txtDate1, and that the text box for the other date is txtDate2.
    <UL><LI>Select txtDate1.
    <LI>Activate the Properties window, then the Event tab of this window.
    <LI>Click in the After Update box.
    <LI>Select Event Procedure from the dropdown list.
    <LI>Click the builder button (the three dots ...) to the right of the dropdown arrow.
    <LI>You will be taken to the Visual Basic Editor. In the code module belonging to the form, the event procedure has already been created for you, but it is empty.
    <LI>Make it look like this:

    Private Sub txtDate1_AfterUpdate()
    Me.txtDate2 = Me.txtDate1 + 30
    End Sub

    <LI>Switch back to Access (Alt+F11) and close & save the form.[/list]I repeat: if the second date is ALWAYS thirty days after the first one, you shouldn't store it in the table, and neither should you use the After Update event as above. Instead, create a query based on the table (sans second date field), and add a calculated field to this query:

    Date2: [Date1]+30

    Use this query as record souce for your form.

Posting Permissions

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