I am relatively new to SQL Server and MS Access and I want to know how to populate certain fields on a new record (in form view) based on the previous record entered. For example, I have three fields Project, RefID and DataType which will be consistent for multiple entries and the users do not want to manually select the value for each field every time they want to input new data. How do I set up a button that when clicked will populate those three fields to what the last input was?
-
Do you want to find data from table for first record of a data entry session or do you just want to carry forward data input into first record? If the latter, use code in each control's AfterUpdate event to set its DefaultValue property. This is a fairly common topic. Review stackoverflow.com/questions/24193828/… and stackoverflow.com/questions/24845816/…June7– June72021-02-10 11:18:50 +00:00Commented Feb 10, 2021 at 11:18
Add a comment
|
1 Answer
Set the DefaultValue, but remember it is a string expression:
Private Sub Project_AfterUpdate()
If Not IsNull(Me!Project.Value) Then
Me!Project.DefaultValue = "" & Me!Project.Value ""
' or, if Project is text:
' Me!Project.DefaultValue = """" & Me!Project.Value """"
End If
End Sub
2 Comments
PV_Shannon
Hi, I have tried this approach and its currently returning #Name?
Gustav
Double-check for typos or other errors. This is a verified method.