Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    Join Date
    Jan 2005
    Location
    Wichita, Kansas, USA
    Posts
    209
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In a continuous form (which is a subform) recording office visits for a patient, I want the "Date" field on the first record for each patient to default to today's date, but each subsequent record to automatically fill in the next calendar day. How would this best be accomplished? Thanks for any help offered.

  2. #2
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Something like this in the Before Insert Event of the Subform might do it.
    You would need to lock the Date field
    Also it will NOT trigger the entry until the first thing is entered on a New Record in another field

    Code:
    Private Sub Form_BeforeInsert(Cancel As Integer)
    
    Dim rst As DAO.Recordset
    Dim dteDate As Date
    
    Set rst = Me.RecordsetClone
    
    'Are there any Other Records
    If rst.RecordCount = 0 Then
        dteDate = Date
    Else
        rst.MoveLast
        dteDate = rst![YourDateField] + 1
    End If
    
    Me![YourDateField] = dteDate
    
    rst.close
    Set rst=Nothing    
    End Sub
    Andrew

Posting Permissions

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