How to Date Stamp a Record in Access

104 19
    • 1). Open Microsoft Access and create a sample database by clicking "File>New>Sample templates>Events," and then the "Create" button. Click the "Navigation Pane" at the left of the screen, then the "Supporting Objects" heading to expose the "Events" table icon. Double-click that icon to open up the Events table for data entry.

    • 2). Enter two rows of sample data in the Events table using the following text, which corresponds to the fields "Title," "Start Time," and "End Time." Don't enter the commas, which show you where to press the "Tab" key. Do replace the <date> fields with today's and tomorrow's dates.

      Cut the grass, <today's date>, <tomorrow's date>
      Paint the house, <today's date>, <tomorrow's date>

    • 3). Begin the programming needed to stamp the Start time automatically, by first creating a form on which the program will run: press "Create>Form." Right-click on the tab of the new "Event" form and select "Design view."

    • 4). Press the "Enable Content" button on the toolbar to allow macros to run on this database.

    • 5). Right-click on the "Date Stamp" field and select "Properties," then click the "Event" tab in the "Property Sheet" window. Click the down-arrow in the "On Got Focus" row and select "[Event procedure]." Click the button with the ellipses, which sits immediately to the right of the down-arrow, to enter the Visual Basic integrated development environment (IDE).

    • 6). Paste the following program code in the IDE's code window:

      Private Sub Start_Time_GotFocus()
      Dim x As Variant
      If (IsNull(Start_Time)) Then
      m = Month(Now())
      d = Day(Now())
      y = Year(Now())
      x = m & "/" & d & "/" & y
      Start_Time = x
      End If
      End Sub

    • 7). Return to Access by pressing "alt-f11," then right-click on the "Events" tab and select "Form View" to activate the form for data entry.

    • 8). Tab through all the fields of each sample record you entered until the "ID" field shows "(New)." Tab down to the "Start time" field and notice the effect of your macro, which has filled in the Start time with the current date.

    • 9). Date stamp the "End Time" field by re-entering the IDE and pasting the following code below the code you previously entered:

      Private Sub End_Time_GotFocus()
      'Change the 1 in the next statement to the desired number of days after the start date
      tm = DateAdd("d", 1, Start_Time)
      End_Time = tm
      End Sub

    • 10

      Re-run the form, ensuring that the "End Time" field displays a date one day after the "Start time" field.

Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.