简体   繁体   中英

MS Access 2010 - make a form populate fields in multiple tables

I am new to access but I have a problem. Take a look at the screenshot of my table relationships. I would like to create a form such that when someone enters the 'Student Code', the student code is populated in all three tables, rather than just one, saving time and confusion as one only needs to type it in once. Thank you everyone in advance. see http://i.stack.imgur.com/bHBqM.png

In the AfterInsert event of the Student Information form, run append VBA queries. With this, each time you add a new Student record, the corresponding student code will be inserted into the other related tables:

DoCmd.RunSQL "INSERT INTO [Parent Information] (Student Code)" _
              & " VALUES (" & Forms!yourformname![Student Code] & ");"
DoCmd.RunSQL "INSERT INTO [Student Medical Conditions] (Student Code) " _
              & " VALUES (" & Forms!yourformname![Student Code] & ");"

Alternatively, you can save the above queries as stored queries and run them via Macro (Open Query) or VBA (DoCmd.OpenQuery) -both still in AfterInsert form event:

DoCmd.OpenQuery "ParentInformationQ"
DoCmd.OpenQuery "StudentMedicalConditionsQ"

If your subforms are included on main form, add Requery commands to update subforms. With this, you will see blank rows appear in subforms, ready for data edit (NOT entry since you created the records in prior queries):

Forms!yourformname!yourparentinfosubformname.Form.Requery
Forms!yourformname!yourmedicalconditionssubformname.Form.Requery

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM