G
GeorgeAtkins
Access 2003.
I import an Excel file into a temp table in order to append new records into
a set of related tables. Because there are no natural keys, I am attempting a
basic match of a combined first-middle-last name. If there is no exact match,
I assume the data is new and append it. The catch: the first,middle,last
names are in separate fields. I'm stuck (my normal state) trying to figure
out how to compare the data in both recordsets. That is, I'm not sure what
method to use that will let me search a table recordset across 3 fields at
one time.
Here is what I have. It works just great if I'm comparing only one name
against another single name, of course.
Set rsImp = db.OpenRecordset("Imported")
Set rsHug = db.OpenRecordset("tblHugMoms")
Set rsBirth = db.OpenRecordset("tblHugBirths")
Set rsBaby = db.OpenRecordset("tblHugBabies")
' get last name from first imported record.
With rsImp
.MoveFirst
Do Until .EOF
' MomLN = .Fields("MTHR_LST_NME") ' ORIGINAL VERSION.
' The FULL NAME I want to seach for...
ImpFullName = .Fields("MTHR_LST_NME") & .Fields("MTHR_FRST_NME")
& .Fields("MTHR_MIDD_NME")
With rsHug
' ********* HERE IS WHERE I AM STUCK.
.FindFirst "MotherLN = """ & MomLN & """"
If .NoMatch Then ' A NEW MOM. WE IMPORT HER DATA
ImpPK = rsImp.Fields(0)
Debug.Print "Adding " & ImpPK & " " & MomLN
.AddNew
.Fields("MotherFN") = rsImp.Fields("MTHR_FRST_NME")
.Fields("MotherMN") = rsImp.Fields("MTHR_MIDD_NME")
.Fields("MotherLN") = rsImp.Fields("MTHR_LST_NME")
.Fields("MailStreet") = rsImp.Fields("MTHR_MAIL_STRT")
.Fields("MailCity") = rsImp.Fields("MTHR_MAIL_CTY")
.Fields("MailState") = "MN" 'rsImp.Fields("MTHR_MAIL_ST")
.Fields("MailZip") = rsImp.Fields("MTHR_MAIL_ZIP")
.Update
' ...
loop
end with
---------------------------------------
So, how can I search a recordset for multiple values at one time? Or is
there a better method? If you need more info, let me know and I'll be happy
to oblige.
Thanks in advance!
george
I import an Excel file into a temp table in order to append new records into
a set of related tables. Because there are no natural keys, I am attempting a
basic match of a combined first-middle-last name. If there is no exact match,
I assume the data is new and append it. The catch: the first,middle,last
names are in separate fields. I'm stuck (my normal state) trying to figure
out how to compare the data in both recordsets. That is, I'm not sure what
method to use that will let me search a table recordset across 3 fields at
one time.
Here is what I have. It works just great if I'm comparing only one name
against another single name, of course.
Set rsImp = db.OpenRecordset("Imported")
Set rsHug = db.OpenRecordset("tblHugMoms")
Set rsBirth = db.OpenRecordset("tblHugBirths")
Set rsBaby = db.OpenRecordset("tblHugBabies")
' get last name from first imported record.
With rsImp
.MoveFirst
Do Until .EOF
' MomLN = .Fields("MTHR_LST_NME") ' ORIGINAL VERSION.
' The FULL NAME I want to seach for...
ImpFullName = .Fields("MTHR_LST_NME") & .Fields("MTHR_FRST_NME")
& .Fields("MTHR_MIDD_NME")
With rsHug
' ********* HERE IS WHERE I AM STUCK.
.FindFirst "MotherLN = """ & MomLN & """"
If .NoMatch Then ' A NEW MOM. WE IMPORT HER DATA
ImpPK = rsImp.Fields(0)
Debug.Print "Adding " & ImpPK & " " & MomLN
.AddNew
.Fields("MotherFN") = rsImp.Fields("MTHR_FRST_NME")
.Fields("MotherMN") = rsImp.Fields("MTHR_MIDD_NME")
.Fields("MotherLN") = rsImp.Fields("MTHR_LST_NME")
.Fields("MailStreet") = rsImp.Fields("MTHR_MAIL_STRT")
.Fields("MailCity") = rsImp.Fields("MTHR_MAIL_CTY")
.Fields("MailState") = "MN" 'rsImp.Fields("MTHR_MAIL_ST")
.Fields("MailZip") = rsImp.Fields("MTHR_MAIL_ZIP")
.Update
' ...
loop
end with
---------------------------------------
So, how can I search a recordset for multiple values at one time? Or is
there a better method? If you need more info, let me know and I'll be happy
to oblige.
Thanks in advance!
george