Default value in a table

P

Pigeon70

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.
 
S

Steve Schapel

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
 
R

Rick Brandt

Pigeon70 said:
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
 
P

Pigeon70

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
 
S

Steve Schapel

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 before:

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top