M
Matiyapak
Hi everybody,
I have a large MS Access Database in which I write regularly words that are
not found in dictionaries.
I wanted to cleanup this Database and get rid of double entries, so I tried
to write a VB program to achieve this (see the program code at the end of
this email).
But when I run this VB program, something strange happens.
The database has four fields: "English, Type, Trad, Remarks"
In the program I wrote 2 loops:
An outer loop (Do Until rstWholeTable.EOF = True) which loops trough all the
records.
An inner loop (Do Until rstDoubleTable.EOF = True) which starts at the
currend record +1 to avoid reading the current record by both loops.
Everytyme the inner loop is finished, I set the outer loop to equal the
inner loop to cance the EOF = TRUE.
When I disable the inner loop (Do Until rstDoubleTable.EOF = True) and run
the program, all the records are tested.
When I disable the outer loop (Do Until rstWholeTable.EOF = True) and run
the program, all the records are tested.
When I enable both loops and run the program, the outer loop is only
processed 2 times, and then EOF becomes TRUE and the program ends.
What is wrong with the program?
TIA,
Matiyapak K.
***********************************************
Sub Double()
Dim dbsDictionary As Database
Dim rstWholeTable As Recordset
Dim rstDoubleTable As Recordset
Dim strTestEng As String
Dim strTestEng1 As String
Set dbDictionary = OpenDatabase("Woorden.mdb")
Set rstWholeTable = dbDictionary.OpenRecordset("Dictionary")
Set rstDoubleTable = dbDictionary.OpenRecordset("Dictionary")
On Error Resume Next
With rstWholeTable
rstWholeTable.MoveLast
rstWholeTable.MoveFirst
End With
Do Until rstWholeTable.EOF = True
strTestEng = rstWholeTable.Fields("English")
strTestType = rstWholeTable.Fields("Type")
strTestTrad = rstWholeTable.Fields("Trad")
strTestRemarks = rstWholeTable("Remarks")
Do Until rstDoubleTable.EOF = True
With rstDoubleTable
.MoveNext
strTestEng1 = rstDoubleTable.Fields("English")
strTestType1 = rstDoubleTable.Fields("Type")
strTestTrad1 = rstDoubleTable.Fields("Trad")
strTestRemarks1 = rstDoubleTable("Remarks")
If strTestEng <> strTestEng1 Then GoTo NoMatch
If strTestType <> strTestType1 Then GoTo NoMatch
If strTestTrad <> strTestTrad1 Then GoTo NoMatch
If strTestRemarks <> strTestRemarks1 Then GoTo NoMatch
With rstDoubleTable
.Edit
.Fields("English").Value = ""
.Fields("Type").Value = ""
.Fields("Trad").Value = ""
.Fields("Remarks").Value = ""
.Update
End With
End With
NoMatch:
Loop
rstWholeTable.MoveNext
Set rstDoubleTable = rstWholeTable
Loop
rstWholeTable.Close
rstDoubleTable.Close
dbsDictionary.Close
Set dbDictionary = Nothing
Set rstWholeTable = Nothing
Set rstDoubleTable = Nothing
End Sub
I have a large MS Access Database in which I write regularly words that are
not found in dictionaries.
I wanted to cleanup this Database and get rid of double entries, so I tried
to write a VB program to achieve this (see the program code at the end of
this email).
But when I run this VB program, something strange happens.
The database has four fields: "English, Type, Trad, Remarks"
In the program I wrote 2 loops:
An outer loop (Do Until rstWholeTable.EOF = True) which loops trough all the
records.
An inner loop (Do Until rstDoubleTable.EOF = True) which starts at the
currend record +1 to avoid reading the current record by both loops.
Everytyme the inner loop is finished, I set the outer loop to equal the
inner loop to cance the EOF = TRUE.
When I disable the inner loop (Do Until rstDoubleTable.EOF = True) and run
the program, all the records are tested.
When I disable the outer loop (Do Until rstWholeTable.EOF = True) and run
the program, all the records are tested.
When I enable both loops and run the program, the outer loop is only
processed 2 times, and then EOF becomes TRUE and the program ends.
What is wrong with the program?
TIA,
Matiyapak K.
***********************************************
Sub Double()
Dim dbsDictionary As Database
Dim rstWholeTable As Recordset
Dim rstDoubleTable As Recordset
Dim strTestEng As String
Dim strTestEng1 As String
Set dbDictionary = OpenDatabase("Woorden.mdb")
Set rstWholeTable = dbDictionary.OpenRecordset("Dictionary")
Set rstDoubleTable = dbDictionary.OpenRecordset("Dictionary")
On Error Resume Next
With rstWholeTable
rstWholeTable.MoveLast
rstWholeTable.MoveFirst
End With
Do Until rstWholeTable.EOF = True
strTestEng = rstWholeTable.Fields("English")
strTestType = rstWholeTable.Fields("Type")
strTestTrad = rstWholeTable.Fields("Trad")
strTestRemarks = rstWholeTable("Remarks")
Do Until rstDoubleTable.EOF = True
With rstDoubleTable
.MoveNext
strTestEng1 = rstDoubleTable.Fields("English")
strTestType1 = rstDoubleTable.Fields("Type")
strTestTrad1 = rstDoubleTable.Fields("Trad")
strTestRemarks1 = rstDoubleTable("Remarks")
If strTestEng <> strTestEng1 Then GoTo NoMatch
If strTestType <> strTestType1 Then GoTo NoMatch
If strTestTrad <> strTestTrad1 Then GoTo NoMatch
If strTestRemarks <> strTestRemarks1 Then GoTo NoMatch
With rstDoubleTable
.Edit
.Fields("English").Value = ""
.Fields("Type").Value = ""
.Fields("Trad").Value = ""
.Fields("Remarks").Value = ""
.Update
End With
End With
NoMatch:
Loop
rstWholeTable.MoveNext
Set rstDoubleTable = rstWholeTable
Loop
rstWholeTable.Close
rstDoubleTable.Close
dbsDictionary.Close
Set dbDictionary = Nothing
Set rstWholeTable = Nothing
Set rstDoubleTable = Nothing
End Sub