Forum Discussion
Using a field value as default for next field
- Mar 11, 2024
Hi,
1. In a table you cannot reference a field name in an expression for a default value. That's why you get the error message.
2. A default value has to be there before or at the latest in the moment when a record is created. That's the point of a default value not only in Access.
3. If I understand your intention correctly then you should use a form for data entry where you can use VBA code to populate the value (not default value) property of a field in the same record to set a standard value or filling aid for the users.
To do this you can use sth like this e.g. in the AfterUpdate event of the Last Name and the First Name control:
Me!FileAs = Me![Last Name] & Me![First Name]
Servus
Karl
****************
Access DevCon - online conference April 18+19
Access Forever
Access News
Access-Entwickler-Konferenz AEK
Apologies for the confusion. If you want the `FileAs` field to be filled with the values from the previous record's `FirstName` and `LastName` fields, you can use the `Form_Current` event. Here's an example of how you can achieve this:
1. In the form's module, add the following code:
```vba
Private Sub Form_Current()
Dim rs As Recordset
If not Me.NewRecord Then ' Code to handle editing a new record
'MsgBox "Editing a new record"
exit sub
End If
Set rs = Me.RecordsetClone
rs.movelast
Me.FileAs.Value = rs.Fields("FirstName").Value & " " & rs.Fields("LastName").Value
rs.Close
Set rs = Nothing
End Sub
```