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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

force creation of child record when parent record is created 1

Status
Not open for further replies.

swtrader

IS-IT--Management
Dec 23, 2004
182
US
I have 2 tables, 1-to-many. Need to create a new child record (with one of its fields having a default value) each time a new parent record is created.



swtrader
-- The trouble with doing something right the first time is that no one appreciates how hard it was.
 
Try an update query - with the default field fed in through the control on the form - that runs whenever a button you make called "save" is pressed.
 
Use the On Insert event of your form where you insert a new record to the parent table.
Code:
Dim strSQL as String
strSQL = "INSERT INTO tblChild (fkField) " & _
  "VALUES(" & Me.pkField & ")"
DoCmd.RunSQL strSQL

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
I think, you could create a (hidden) subform linked with the master/child field property to the mainform. Everytime a new record is created in the master, a child record is created too.

Pampers [afro]
There is only one way to change a diaper - fast
 
pampers,
I don't think so. Just creating a related subform will not insert a record into a child table.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
oeps... sorry guys, I'm mistaken.


Pampers [afro]
There is only one way to change a diaper - fast
 
ah, 't is so simple when you know how. Thanks, dhookup. I shudda but didn't think of the SQL INSERT.

swtrader
-- The trouble with doing something right the first time is that no one appreciates how hard it was.
 
I would probably add code to check for a child record first prior to inserting a record into the child table.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top