PC Review


Reply
Thread Tools Rate Thread

Default value in a table

 
 
Pigeon70
Guest
Posts: n/a
 
      3rd Nov 2008
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.
 
Reply With Quote
 
 
 
 
Steve Schapel
Guest
Posts: n/a
 
      3rd Nov 2008
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.

 
Reply With Quote
 
Rick Brandt
Guest
Posts: n/a
 
      3rd Nov 2008
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


 
Reply With Quote
 
Pigeon70
Guest
Posts: n/a
 
      3rd Nov 2008
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.

>

 
Reply With Quote
 
Steve Schapel
Guest
Posts: n/a
 
      3rd Nov 2008
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.

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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Default Value =now() in table Steve Stad Microsoft Access Database Table Design 2 1st Feb 2010 04:14 PM
Default Value from Another Table MollyDog8 Microsoft Access Getting Started 2 13th Jan 2009 10:18 AM
Can a record in a table have a default value from another table? gtslabs Microsoft Access Forms 3 10th Dec 2008 09:44 PM
Pivot Table - Default Settings for Table Options =?Utf-8?B?TmFjaG8=?= Microsoft Excel Misc 0 25th Feb 2005 06:05 PM
Default value of a Table in Sql server To default value in DataSet scheme itzik Microsoft ADO .NET 9 15th Feb 2005 01:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:47 AM.