ms access insert multiple rows into parent child tables -
hi i've been trying adapt prior stack overflow post situation coming short. have 2 ms access tables in parent child relationship (one many). i'm trying write vba insert 1 record parent table , multiple records child table. saw post close want 1 one relationship. provide me example of how multiple rows in child table?
how can make new records cascade across 1 one relationship in ms access?
i'm using ms access 2010 , i'm writing vba module in ms excel 2010.
it relates how connect "many" entries table "one" table. (unless i'm missing point of question.) example works illustrate:
option explicit sub addclasswithstudents() dim tblclass recordset dim tblstudents recordset dim db database dim classid long dim newkids() string dim kid variant set db = dbengine(0).opendatabase("database1.accdb") set tblclass = db.openrecordset("tblclasses", dbopendynaset) set tblstudents = db.openrecordset("tblstudents", dbopendynaset) '--- add new class tblclass.addnew tblclass("title").value = "calculus" tblclass("teacher").value = "einstein" tblclass.update tblclass.bookmark = tblclass.lastmodified 'makes current record classid = tblclass("id").value '--- add students newkids = split("tom,dick,harry,suzie,mary", ",", , vbtextcompare) each kid in newkids tblstudents.addnew tblstudents("classid").value = classid tblstudents("studentname").value = kid tblstudents.update next kid db.close set tblstudents = nothing set tblclass = nothing set db = nothing end sub
Comments
Post a Comment