Having a new form for one table insert something automatically into another table...

  • Thread starter Thread starter Crispy
  • Start date Start date
C

Crispy

Hi,

I'm very new to this so I appologize ahead of time for a dumb question.

I'm building a very simple student database. The main student form has all
their student information in it (that it stores in the student table) and
then a button on it called "Parent Information..." that launches another
form so that you can enter that student's parent information (into the
parents table). The two tables are related by student ID.

Everything works great for existing records, however as soon as you try to
add a new student, the Student form fills in the student ID with a new
autonumber (which is good). But then when you hit the "Parent
Information..." button and that form launches... the newly assigned student
ID number is not on that form. How do I make it so when they add a new
student, and a new student ID is made, that it will be inserted into that
field for the parents form---so that the relationships work.

Thanks agian!

Abby
 
in the Parents form's BeforeUpdate property, add a procedure to run the
following code

If IsNull(Me!StudentID) Then
Me!StudentID = Forms!StudentFormName!StudentID
End If

substitute the correct form and control names, of course. this will add the
StudentID from the open Students form to the new record in the Parents form
when the record is saved.

hth
 
I'm guessing I did something wrong, but I didn't get it to work. Thanks for
help and patience.

I inserted the code you mentioned into the beforeupdate property of the
Students Parent Information form. When you hit the "new form" button to
launch a blank new Student Records form "Autonumber" appears beside student
ID. You fill that form out and then hit the button to launch the Student
Parent Information form... this form launches and first nothing appears in
the StudentID field...but after you tab down to another field on the form a
zero appears in the field for StudentID. If you keep filling out the form
with the parent's infomation, and then close the form (meanwhile the main
Student Records form is still open in the background) a Compile error:
syntax error with Me!StudentID = Forms!Student Parent Information!StudentID
appearing in red occurs.

I'm hoping this makes sense. I'm not sure if there is a problem because the
main Student Records Form isn't saved first before the Student Parent
Information form launches...and therefore the code isn't able to get teh
StudentID # from the first form? I really have no idea. Any help is
appreciated.

Thanks again,

Abby

P.S. Form names are:
Student Emergency Contacts
Student Parent Information
Student Records
Switchboard
Tuition

Field name is:
StudentID
 
Back
Top