A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Default value in a table



 
 
Thread Tools Display Modes
  #1  
Old November 3rd, 2008, 12:28 AM posted to microsoft.public.access
Pigeon70
external usenet poster
 
Posts: 7
Default 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  
Old November 3rd, 2008, 12:43 AM posted to microsoft.public.access
Steve Schapel
external usenet poster
 
Posts: 1,422
Default 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  
Old November 3rd, 2008, 12:48 AM posted to microsoft.public.access
Rick Brandt
external usenet poster
 
Posts: 4,354
Default 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  
Old November 3rd, 2008, 02:50 AM posted to microsoft.public.access
Pigeon70
external usenet poster
 
Posts: 7
Default 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  
Old November 3rd, 2008, 03:10 AM posted to microsoft.public.access
Steve Schapel
external usenet poster
 
Posts: 1,422
Default 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

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:04 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.