If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Default value in a table
Hi there,
I have a table called 'Person' which has two fields: 'First Name' and 'Preferred Name'. For the field 'Preferred Name' I want to set the default value to be the same as in the 'First Name' field unless something different is added in the 'Preferred Name' field. I keep getting syntax errors because I don't really understand about writing expressions. Can someone please help me with the correct expression to put in the 'Preferred Name' default value? This would be much appreciated. |
#2
|
|||
|
|||
Default value in a table
Pigeon,
You won't be able to apply a Default Value in this scenario. Default Value only applies at the point where a new record is being created. By the time we know what the First Name is, it's too late. You can use a VBA procedure on the After Update event of the First Name control, something like this: If IsNull(Me.Preferred_Name) Then Me.Preferred_Name = Me.First_Name End If -- Steve Schapel, Microsoft Access MVP Pigeon70 wrote: Hi there, I have a table called 'Person' which has two fields: 'First Name' and 'Preferred Name'. For the field 'Preferred Name' I want to set the default value to be the same as in the 'First Name' field unless something different is added in the 'Preferred Name' field. I keep getting syntax errors because I don't really understand about writing expressions. Can someone please help me with the correct expression to put in the 'Preferred Name' default value? This would be much appreciated. |
#3
|
|||
|
|||
Default value in a table
Pigeon70 wrote:
Hi there, I have a table called 'Person' which has two fields: 'First Name' and 'Preferred Name'. For the field 'Preferred Name' I want to set the default value to be the same as in the 'First Name' field unless something different is added in the 'Preferred Name' field. I keep getting syntax errors because I don't really understand about writing expressions. Can someone please help me with the correct expression to put in the 'Preferred Name' default value? This would be much appreciated. You cannot do what you want at the table level. The default value is applied before your first keystroke so it would already be set before you enter a value in your "First Name" field. You can use the BeforeUpdate event of a *Form* that you use to enter records... If IsNull(Me.PreferredName) _ And Not IsNull(Me.FirstName) Then Me.PreferredName = Me.FirstName End If -- Rick Brandt, Microsoft Access MVP Email (as appropriate) to... RBrandt at Hunter dot com |
#4
|
|||
|
|||
Default value in a table
Hi Steve,
Thanks so much for your answer! Do you mean like this? If so then something isn't working. Private Sub First_Name_AfterUpdate() If IsNull(Me.Preferred_Name) Then Me.Preferred_Name = Me.First_Name End If End Sub "Steve Schapel" wrote: Pigeon, You won't be able to apply a Default Value in this scenario. Default Value only applies at the point where a new record is being created. By the time we know what the First Name is, it's too late. You can use a VBA procedure on the After Update event of the First Name control, something like this: If IsNull(Me.Preferred_Name) Then Me.Preferred_Name = Me.First_Name End If -- Steve Schapel, Microsoft Access MVP Pigeon70 wrote: Hi there, I have a table called 'Person' which has two fields: 'First Name' and 'Preferred Name'. For the field 'Preferred Name' I want to set the default value to be the same as in the 'First Name' field unless something different is added in the 'Preferred Name' field. I keep getting syntax errors because I don't really understand about writing expressions. Can someone please help me with the correct expression to put in the 'Preferred Name' default value? This would be much appreciated. |
#5
|
|||
|
|||
Default value in a table
Pigeon,
Yes, that's pretty much what I mean, except the first line of code needs to be broken to a new line, same as I showed you befo Private Sub First_Name_AfterUpdate() If IsNull(Me.Preferred_Name) Then Me.Preferred_Name = Me.First_Name End If End Sub If that still doesn't work, let us know what actually happens. -- Steve Schapel, Microsoft Access MVP Pigeon70 wrote: Hi Steve, Thanks so much for your answer! Do you mean like this? If so then something isn't working. Private Sub First_Name_AfterUpdate() If IsNull(Me.Preferred_Name) Then Me.Preferred_Name = Me.First_Name End If End Sub |
Thread Tools | |
Display Modes | |
|
|