Pls Help - default value in a subform

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
 
J

John W. Vinson

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
 

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

Top