W
Wissam
Hi,
Every few months, I recieve a table that includes patients who have high
blood Cholesterol. I want to import from that table the patients who are
"new" to our clinic and have not been seen before by us, and keep the ones
that have been seen by us before.
The code that I have below appends records from “SourceTable†to
“TargetTableâ€. Both tables are set to have the same field names and structure
(such as ID, Name,… ). [ID] in the TargetTable is set as a primary key and
its format is text (something like ab1234, dd2345,..). I want to amend the
code so that it deletes records in SourceTable that get copied to TargetTable
and keep the ones that were not transferred (because they already exist in
the TargetTable); therefore, my goal is:
For each recordset in SourceTable, check if SourceTable.[ID] exists already
among the recordsets in TargetTable.[ID] fields. If not, then transfer the
record to TargetTable and delete it from the SourceTable. If it does exist,
then keep it in SourceTable.
Thanks a lot for any suggestions:
My current Code is as follows:
-------------------------------------------
Dim db As DAO.Database
Dim rsSource As DAO.Recordset
Dim rsTarget As DAO.Recordset
Set db = CurrentDb()
Set rsSource = db.OpenRecordset("SourceTable")
Set rsTarget = db.OpenRecordset("TargetTable")
rsSource.MoveFirst
Do Until rsSource.EOF
rsTarget.AddNew
rsTarget![ID] = rsSource![ID]
rsTarget![Name] = rsSource![Name]
….
rsTarget.Update
rsSource.MoveNext
Loop
------------------------------------------------------------------
Every few months, I recieve a table that includes patients who have high
blood Cholesterol. I want to import from that table the patients who are
"new" to our clinic and have not been seen before by us, and keep the ones
that have been seen by us before.
The code that I have below appends records from “SourceTable†to
“TargetTableâ€. Both tables are set to have the same field names and structure
(such as ID, Name,… ). [ID] in the TargetTable is set as a primary key and
its format is text (something like ab1234, dd2345,..). I want to amend the
code so that it deletes records in SourceTable that get copied to TargetTable
and keep the ones that were not transferred (because they already exist in
the TargetTable); therefore, my goal is:
For each recordset in SourceTable, check if SourceTable.[ID] exists already
among the recordsets in TargetTable.[ID] fields. If not, then transfer the
record to TargetTable and delete it from the SourceTable. If it does exist,
then keep it in SourceTable.
Thanks a lot for any suggestions:
My current Code is as follows:
-------------------------------------------
Dim db As DAO.Database
Dim rsSource As DAO.Recordset
Dim rsTarget As DAO.Recordset
Set db = CurrentDb()
Set rsSource = db.OpenRecordset("SourceTable")
Set rsTarget = db.OpenRecordset("TargetTable")
rsSource.MoveFirst
Do Until rsSource.EOF
rsTarget.AddNew
rsTarget![ID] = rsSource![ID]
rsTarget![Name] = rsSource![Name]
….
rsTarget.Update
rsSource.MoveNext
Loop
------------------------------------------------------------------