Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Autonumber to subform for new record

Status
Not open for further replies.

dolfin13

Programmer
Jun 29, 2005
22
US
I have a data entry form with a subform. The main form is used to enter the Task information while the subform is used to enter and list specific details associated with this new task. The subform is a continuous form that will not show any records at first but will allow new details to be added.

The Detail table is related to the Task table by the Tasks ID number (autonumber). My problem is I can't pass the new autonumber to the subform because the subform opens first.

Any help would be appreciated

Thanks
 
Hi
What do you mean "because the subform opens first."? Usually, Access will fill the child field in, when you have a subform and a main form linked by a field.
 
Sorry for being confusing. With the innermost subform being loaded first, the autonumber of the mainform (that gets created for the new record) doesn't happen until after the subform is already loaded. But I need the new ID number from the main form to relate the Details to the Task.

Again, I'm sorry for being a bit confusing. I think I may have come up with an answer to my problem. I am going to try to set the form links and the pass the value with a "NEW" command button after the forms load. I will post if my proposed solution works out.
 
How are ya dolfin13 . . . . .

Not trying to sound demeaning here . . . at all, but this is all cut & dried for programmers in the know. [blue]In a form [purple]properly linked[/purple] with a subform, you won't see the new AutoNumber until you edit a new record![/blue]

Calvin.gif
See Ya! . . . . . .
 
I realize this... that was the problem. I needed this new autonumber that gets created from the main form to be a value in the subform's new data entry field. This field is the link between the subform and the main form. I realize that when the form is opened, the subform will have zero records, but I need to be able to add new 'details' to this subform. As it stands right now, I can add the 'details in the table just fine, but the autonumber from the mainform is not getting added to the record so I'm not getting any relationship.

I'm apologoze, I'm obviously not good at communicating my situtation.

I did get this working, I am passing the autonumber from main form with the 'before update' event of one of the fields in the subform.

Thanks for the reply's
 
dolfin13 . . . . .

By chance . . . . are you trying to edit a new record in the subform before editing a new record in the mainform?

Calvin.gif
See Ya! . . . . . .
 
No, but Access would make it seem that way since the innermost subforms are loaded first. I was mistakenly trying to pass the autonumber from the main form to the subform before the new autonumber was being created.
 
dolfin13 said:
[blue] . . . but Access would make it seem that way since the innermost subforms are loaded first. . . .[/blue]
This is just a matter of loading when the form opens. Once fully opened, data entry follows you relationships . . . that is:
Microsoft said:
[blue]You can't have a record in a [blue]Child Table[/blue] without a related rcord in the [blue]Parent Table[/blue].[/blue]
The above relating to [blue]Primary Keys[/blue] in relationships . . . of course.

For the relationships between you main tables and child tables, you should have [blue]Referential Integrity[/blue] turned on.

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top