default value

P

Pass-the-reality

I have a form called frmAssociateInfo. Within this form I have a field called
FirstName and a field called LastName. On my subform (frmSubInfo) I have
field called Associate. I want to set the default to equal FirstName and
LastName. I tried using the below default value, but it did not work.

=[Forms]![frmAssociateInfo]![FirstName] And
[Forms]![frmAssociateInfo]![LastName]
 
S

Steve Schapel

Pass,

Try it like this:
=[Forms]![frmAssociateInfo]![FirstName] & " " &
[Forms]![frmAssociateInfo]![LastName]

.... or:
=[Parent]![FirstName] & " " & [Parent]![LastName]

Please be aware, though, that the Default Value only applies at the
point where a new record is being created. Using the Default Value in
these circumstances may be a bit problematic, and you may be better to
look at using code to assign the value to the Associate control, perhaps
on the Before Insert event of the subform.
 
K

Ken Sheridan

You can 'push' it in with code in the parent form's Current event procedure
with:

Me.YourSubformControl.Form.FirstName.DefaultValue = _
"""" & Me.LastName & " " & Me.LastName """"

You should also put the same code in the parents form's AfterInsert event
procedure to cater for when a new record is entered in the parent form.

Note that YourSubformControl is the name of the control in the parent form's
Controls collection which houses the subform and may or may not be the same
as the name of the underlying form object frmSubInfo.

Another point to note is that the DefaultValue property is always a string
expression regardless of data type and in code should be wrapped in literal
quotes characters as above. Most of the time it won't matter if you omit the
quotes characters, but in some circumstances they are crucial when you might
not expect them, dates being a case in point (and with dates don't be tempted
to use the # date delimiter character instead – it will fail if the value is
not in US short date or an otherwise internationally unambiguous date format).

However, if the Associate control in the subform is a bound control then I
do wonder whether you are redundantly repeating the values in two tables. If
its an unbound control and you merely want this control to show the current
associate's full name from the parent form then simply set its ControlSource
property to:

=Parent.Firstname & " " & Parent.LastName

Ken Sheridan
Stafford, England
 
J

Jeff Boyce

As Ken has pointed out, redundantly storing the same data (LastName and
FirstName) twice is probably unnecessary (and opens your db up to data
integrity issues). Why not just use the PersonID in the table behind the
subform, and use a query to get the LastName and FirstName for that
PersonID?

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
K

Ken Sheridan

Jeff:

I flagged that issue up just in case, but as the OP wants the concatenated
full name in it I suspect the control in the subform is more likely to be an
unbound one. A computed column concatenating the two names in the subform's
underlying query, then binding a control in the subform to the column, is
probably the simplest and most efficient solution, as you suggest.

Mind you, why is the name is needed at all in the subform, when its already
visible in the parent form?

Ken Sheridan
Stafford, England

Jeff Boyce said:
As Ken has pointed out, redundantly storing the same data (LastName and
FirstName) twice is probably unnecessary (and opens your db up to data
integrity issues). Why not just use the PersonID in the table behind the
subform, and use a query to get the LastName and FirstName for that
PersonID?

Regards

Jeff Boyce
Microsoft Office/Access MVP


Pass-the-reality said:
I have a form called frmAssociateInfo. Within this form I have a field
called
FirstName and a field called LastName. On my subform (frmSubInfo) I have
field called Associate. I want to set the default to equal FirstName and
LastName. I tried using the below default value, but it did not work.

=[Forms]![frmAssociateInfo]![FirstName] And
[Forms]![frmAssociateInfo]![LastName]
 
J

Jeff Boyce

Yah! I wondered that myself...

Jeff

Ken Sheridan said:
Jeff:

I flagged that issue up just in case, but as the OP wants the concatenated
full name in it I suspect the control in the subform is more likely to be
an
unbound one. A computed column concatenating the two names in the
subform's
underlying query, then binding a control in the subform to the column, is
probably the simplest and most efficient solution, as you suggest.

Mind you, why is the name is needed at all in the subform, when its
already
visible in the parent form?

Ken Sheridan
Stafford, England

Jeff Boyce said:
As Ken has pointed out, redundantly storing the same data (LastName and
FirstName) twice is probably unnecessary (and opens your db up to data
integrity issues). Why not just use the PersonID in the table behind the
subform, and use a query to get the LastName and FirstName for that
PersonID?

Regards

Jeff Boyce
Microsoft Office/Access MVP


Pass-the-reality said:
I have a form called frmAssociateInfo. Within this form I have a field
called
FirstName and a field called LastName. On my subform (frmSubInfo) I
have
field called Associate. I want to set the default to equal FirstName
and
LastName. I tried using the below default value, but it did not work.

=[Forms]![frmAssociateInfo]![FirstName] And
[Forms]![frmAssociateInfo]![LastName]
 
S

Steve Schapel

I interpreted it differently. Having something as a default value to me
implies the option to change it. I can think of a number of examples in
my own work where a child record has a default value taken from the
parent record, but may at times be different so editing may be
necessary. We are of course just speculating, and unless
Pass-the-reality spills the beans we will never know. But to me it
makes perfect sense to want to by default set the value of a bound
control on a subform, derived from data from the main form.
 
K

Ken Sheridan

Steve:

Exactly, but reading between the lines my gut feeling is they're using the
property inappropriately. But, as you say, we may never know.

Ken Sheridan
Stafford, England
 
E

elisregina

Pass-the-reality said:
I have a form called frmAssociateInfo. Within this form I have a field
called
FirstName and a field called LastName. On my subform (frmSubInfo) I have
field called Associate. I want to set the default to equal FirstName and
LastName. I tried using the below default value, but it did not work.

=[Forms]![frmAssociateInfo]![FirstName] And
[Forms]![frmAssociateInfo]![LastName]
 

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

Similar Threads


Top