View Single Post
  #9  
Old November 9th, 2009, 12:25 PM posted to microsoft.public.access.forms
BruceM via AccessMonster.com
external usenet poster
 
Posts: 448
Default Create subform default values based on value set in main form

I would use Me.SubformField.Value, same as referencing the main form. The
Value property is default, so it is optional. That is, if it is left off the
Value will be used.

Be sure SubformField is not 0 (for a number field) or a zero-length string
(text). Neither of these are the same as Null, which essentially means
"unkonwn".

Another possibility, if the SubformField value is to be entered in new
records, is to use DefaultValue. In the subform's Current event:
Me.SubformField.DefaultValue = Me.Parent.MainFormField

DefaultValue applies only to new records, so it may not be what you need, but
it is sure to come in handy at some point if not here.

The subform control is the "box" on the main form containing the subform. If
you are referencing a subform field or control from the main form you need to
reference the Form property of the subform control:
Me.[SubformControlName].Form.[FieldName].

Note that the subform control may not have the same name as the subform
itself.

If the field and control names contain only alphanumeric characters and
underscores you do not need to use square brackets, but I used them here in
the hope it makes it easier to sort out.


Benjamins wrote:
Hi,

Below is a code that i change base form your coding

Private Sub SubformField_Enter()
If IsNull(SubformField.Value) Then SubformField.Value= Me.Parent.
MainformField.Value
End Sub

Thank you very much for the response, Benjamins!

[quoted text clipped - 13 lines]

If there are any other suggestions, I'd be very glad to hear them!


--
Message posted via http://www.accessmonster.com