Auto populate date field based on first date field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dylankirs
    New Member
    • Jul 2020
    • 4

    Auto populate date field based on first date field

    Hi. New to Access and would appreciate any help!

    I'm working on a Multiple Items form and want to populate the date field in the 2nd, 3rd, 4th, etc. line with the date selected in the 1st line.

    Example: 1st line = 7/25/20
    2nd, 3rd, 4th, and on = same date
  • isladogs
    Recognized Expert Moderator Contributor
    • Jul 2007
    • 479

    #2
    if you are happy to copy the date in the previous row manually, just click Ctrl+' (apostrophe).
    However if that's not suitable for your needs, why not search for something like "Access Fill Down to Emulate Excel Fill Down".

    Hope that helps
    Last edited by NeoPa; Aug 1 '20, 01:23 AM.

    Comment

    • cactusdata
      Recognized Expert New Member
      • Aug 2007
      • 223

      #3
      Have a button to run this simple code to fill/update the date field of the records using the RecordsetClone, thus update the form instantly:

      Code:
      Private Sub FillDateButton_Click()
      
          Dim Records     As DAO.Recordset
          
          Dim FirstDate   As Date
          
          Set Records = Me.RecordsetClone
          
          If Records.RecordCount > 0 Then
              Records.MoveFirst
              FirstDate = Records!YourDateFieldName.Value
              Records.MoveNext
              While Not Records.EOF
                  Records.Edit
                      Records!YourDateFieldName.Value = FirstDate
                  Records.Update
                  Records.MoveNext
              Wend
          End If
          Records.Close
      
      End Sub

      Comment

      • jimatqsi
        Moderator Top Contributor
        • Oct 2006
        • 1290

        #4
        In CactusData's code, addd
        Code:
        if me.dirty then me.dirty=false
        prior to line 7. That will make sure there are not any unsaved changes before you get into the code.

        Comment

        • Naheedmir
          New Member
          • Jul 2020
          • 62

          #5
          You have to give the same field names for all those fields in which you want to have the same value. Select all fields and click on the Binding tab. Then in the default binding, click on Global. Thus now, when you enter a date in the date1 field, it will show the same value for all selected fields.

          Comment

          • dylankirs
            New Member
            • Jul 2020
            • 4

            #6
            Thank you to everyone that replied. I decided remove the date field. Hope these answers help someone else with this problem!

            Comment

            Working...