form/subform issue


B

Beth

I have run into a situation with a form/subform that I can't resolve. I am
open to suggestions.

The main form has 3 fields on it, a date with a default value, the id field
which is an autonumber, and one text field. Because of the autonumber and
the default date, a user has to enter something in the text field to
generate a record in the main form.
Frequently our users are going straight to the subform and so they get an
error that no record matches in the main form.
Is there any event/code/command I can use so that when they try to put a
record in the subform, it checks for a null id in the main form and
generates a record there?
I tried some code on the before update event for the first field in the
subform (a combo box) to add some text to that text field. That generates
an autonumber in the main form and in the matching subform. However, it
doesn't update that record to the underlying table, so I still get the
error.

I really need some help on this, so I am open to any suggestions you have.

Thanks!
Beth
 
Ad

Advertisements

T

tina

since the date field in the main form has a default value anyway, suggest
you remove the DefaultValue setting, and add it via code in the subform. try
adding the following code to the *subform's* BeforeInsert event procedure,
as

With Me.Parent
If .NewRecord Then
!aDate = <the default date value>
.Dirty = False
End If
End With

"Parent" refers to the subform object's parent object, which is the main
form. adding the date value triggers the Autonumber primary key, and setting
the main form's Dirty property to False saves the record to disk, so the PK
value is available to the subform record.

hth
 
B

Beth

Perfect! The .Dirty=False line is what made the difference for me. I had
not been able to get it to save the record to disk.
I really appreciate the help.
Beth
 
Ad

Advertisements

T

tina

you're welcome :)


Beth said:
Perfect! The .Dirty=False line is what made the difference for me. I had
not been able to get it to save the record to disk.
I really appreciate the help.
Beth
 

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