
Originally Posted by
KP_SoCal
So essentially I would need a VBA module the would match up the MasterTable fields from a record with corresponding fields in the record from Table1.
I think the one thing you are missing here is the coverage of all the "what if's" in a situation like this. Before you run the code I've written, make a new field in table1, call it "fldupdated" and make it a BOOLEAN type. make the default value "false" in table design view.
after the new field, here's the solution to use if you read it the way I read it:
Code:
function kp()
dim ctr as integer
dim updaterec as boolean
dim db as dao.database
dim rs as dao.recordset
dim rs2 as dao.recordset
set db = currentdb
set rs = db.openrecordset("SELECT " & _
"fldProd, fldPio, fldFam, fldSer, fldTra, fldInt, fldupdated " & _
"FROM table1", dbopendynaset)
set rs2 = db.openrecordset("SELECT " & _
"fldProd, fldPio, fldFam, fldSer, fldTra, fldInt " & _
"FROM mastertable", dbopendynaset)
rs.movefirst
rs2.movefirst
with rs2
do until .eof
do until rs.eof
if rs!fldupdated = 0 then
updaterec = true
for ctr = 0 to 5
if not isnull(.fields(ctr)) then
if .fields(ctr) <> rs.fields(ctr) then
updaterec = false
exit for
end if
end if
next ctr
if updaterec = true then
rs.edit
rs!fldprod = iif(isnull(!fldprod), null, !fldprod)
rs!fldPio = iif(isnull(!fldPio), null, !fldPio)
rs!fldFam = iif(isnull(!fldFam), null, !fldFam)
rs!fldSer = iif(isnull(!fldSer), null, !fldSer)
rs!fldTra = iif(isnull(!fldTra), null, !fldTra)
rs!fldInt = iif(isnull(!fldInt), null, !fldInt)
rs!fldupdated = -1
rs.update
end if
end if
rs.movenext
loop
.movenext
rs.movefirst
loop
end with
rs.close
rs2.close
set db = nothing
set rs = nothing
set rs2 = nothing
end function
This of course says that more than one rec in table1 can be updated from the same record in mastertable. But then again, that's how I read it...