Find Record, if not found add new

17PSI

New member
Local time
Today, 16:56
Joined
Nov 1, 2001
Messages
6
I have a Parent form and Child form each with a corresponding table. The Parent table has ParentID as Auto number for the primary key, the Child table has childID as Auto number for the primary key and ParentID as the foreign key. The user enters a new parent or looks up an existing parent record (on the Parent form). I have a button on the parent form that when clicked will open the related child records (Child Form). I would like to add another button to the Parent form to add a new child for that parent. It would need to open the Child form and make the assocation with the ParentID and allow the user to enter the new child information.

Thanks!
 
Just put the child form as a subform on the parent form, with the ParentID as Master/Child Links properties of the subform object. Then using the navigations buttons on the subform, add children at will.
 
I was looking to try and achieve the same thing but don't want to use a sub form. My parent has about 8 different sub Items and I wanted to put the buttons on the main form and have the sub forms pop up when each button is pressed.

I have achieved this but it only works if theer is already a record in the sub form relate dto the parent, if there is no record in the sub form related to the main form I want to add a new one.
 
Last edited:
Thanks for the reply llkhoutx I however would prefer not to use a subform, because there is so much data that needs to be entered. It tends to get confusing puting that much into a subform.
 
Have you tried saving the record first before you open the linked form?
 
docmd.openform "frmchild",,,"ParentID=" & me!ParentID
 
Yes the record is saved before the form is opened. Here is an example of what is happening: The user opens the Parent form and enters the info, then they click on a Child/Children button. If the parent has children already entered it will populate the child form with their corresponding child data in the form. However if they do not have any children already entered a blank child form will open, however it does not associate with the parent. So if you enter in the child info and close the data is lost. llkhoutx
just saw your response, I'll give it a shot.
 
put the following code into childform (onOpen)
If Me.Recordset.BOF And Me.Recordset.EOF Then
DoCmd.GoToRecord , , acNewRec
parentid = forms.parentform.parentid
End If


in parent form, make sure the button to open child has this

on error resume next
 

Users who are viewing this thread

Back
Top Bottom