I'm trying to create a file of employees with their dependents. I have created this procedure to sort the people but I'm getting duplicate dependents in some cases but not all. I'll appreciate any input. Thanks. Private Sub ExportMain() Dim LogFile As Integer LogFile = FreeFile Dim LogFileName As String LogFileName = "C:\EligFile.txt" Dim DepNotFound As Boolean Dim rstMain As Recordset Dim rstDep As Recordset Dim db As Database Set db = CurrentDb() Set rstMain = db.OpenRecordset("tblMainParts") Set rstDep = db.OpenRecordset("tblDeps2") Open LogFileName For Append As #LogFile Do While Not rstMain.EOF 'Main Subscriber Print #LogFile, Left(rstMain!Field1 & Space(680), 680) 'Move through dependent records until Dep SSN matches with Main SSN Do While Left(rstMain!Field1, 9) <> Left(rstDep!Field1, 9) rstDep.MoveNext If (rstDep.EOF = True) Then DepNotFound = True Exit Do Else DepNotFound = False End If Loop 'Write Dependent records while Dep SSN matches with Main SSN If (DepNotFound = False) Then Do While (Left(rstMain!Field1, 9) = Left(rstDep!Field1, 9)) Print #LogFile, Left(rstDep!Field1 & Space(680), 680) rstDep.MoveNext If (rstDep.EOF = True) Then Exit Do End If Loop End If rstMain.MoveNext rstDep.MoveFirst Loop Close #LogFile End Sub