Pls Help - default value in a subform

  • Thread starter Thread starter Matt Spoljarevic
  • Start date Start date
M

Matt Spoljarevic

Hello,

Could someone please help with the following(my knowledge of coding is very
basic):

I have created a form Called "Invoice Entry" from a table called
"Workorders" this contains a field called "work request"

I have a sub-form based on a table called "ACM Checklist" this contains a
Field called "Description"

The Forms are linked by a "Workorder Number"

I would like to have the Sub-form's "description" field (if it is null) to
default to the value of the Form's "Work Request" Field when the form loads.

I only want this to happen if it is null initially, because we will be
changing the details as needed.

Any help would be appreciated

Regards

Matt
 
Hello,

Could someone please help with the following(my knowledge of coding is very
basic):

I have created a form Called "Invoice Entry" from a table called
"Workorders" this contains a field called "work request"

I have a sub-form based on a table called "ACM Checklist" this contains a
Field called "Description"

The Forms are linked by a "Workorder Number"

I would like to have the Sub-form's "description" field (if it is null) to
default to the value of the Form's "Work Request" Field when the form loads.

I only want this to happen if it is null initially, because we will be
changing the details as needed.

Any help would be appreciated

Regards

Matt

If (and only if!) the value is not redundant - it may legitimately be the same
but it may also be altered for this child record, while being left alone in
the parent table - you can use just a line of code to do this.

Open the Subform in design view, view its Properties, and find the "Before
Insert" property. Click the ... icon by it and choose Code Builder. Access
will give you a Sub and End Sub line; edit them to

Private Sub Form_BeforeInsert(Cancel as Integer)
Me![Description] = Parent![Work Request]
End Sub

The BeforeInsert event fires at the first keystroke in the new record on the
subform, so the description field will necessarily be null, so there's no need
to check it (in my opinion).
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 
Back
Top