简体   繁体   中英

How to reuse data in multiple records in Access form

Big question: How can I make Access automatically fill in a cell in a form based on previously entered data?

I need to enter leave details for members of staff. I tend to enter these by date, and in one to two week chunks. Is there a way to have the next new record automatically fill in the date part of the record with the previously entered one?

Table structure
Staff: StaffID, Name
Absences: ID, StaffID, Dateaway, OtherDetails

I want it to automatically fill in DateAway with the entry of the row above it, or the previously entered row, as I will enter say 10 dates in a fortnight, but 50 entries over those dates. I enter them chronologically, and after the fact (So just defaulting to TODAY() won't work).

There's a shortcut Ctrl+' that does pretty much what I need, wondering if there's a way to do that with the generation of a new record.

You have to be careful with this. If your form is bound to a table/query, you're going to insert a junk record every time you're done with the form. However, if it's unbound you can do this using DMAX, in the After Insert event of the form.

Private Sub Form_AfterInsert() 
   txtDateaway.Text = DMax("Dateaway", "Absences", "StaffID = " & Me.txtStaffID) 
End Sub

This is, of course, assuming your Dateaway field on your form is called txtDateaway and your StaffID field is called txtStaffID.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM