R
Ray C
Help please
I am looking to find all the occurences in a table where one of the Fields
holds a "Serial Number" and another field holds the "Contract Number". The
Serial Numbers are unique and the Contract Numbers are the same. So, I want
to search through my Table, searching every record for a field that matches
my Contract Number Criterion and pick out the corresponding unique serial
number.
Easy, I thought. Just FindFirst Criteria, followed by a loop to FindNext
Criterion. the Loop to be terminated by an EOF.
When I did this the loop continued to run well after the last racord in the
Table had been found. (I thought thay the loop would exit after it had found
the last matching Critera)
So I came up with a solution whereby I did a Find First, store that record
in the variable "First", followed by a FindLast and store that record in the
variable "Last". I then would compare each record in the Find Next Loop with
the Variable "Last" and use that to exit wen FindNext = "Last". However, My
initial attempts gives me the results where "First" contains the first Serial
Number that matches the Contract Number, Great, Unfortunately the vatriable
Last = the same Serial Number. The loop works great and finds all of the
other serial numbers that have the same Contract Number but I have no method
of jumping out of the loop when I get to the last Matching Record.
I must be missing something,, can anyone help? I enclose my "Play" code
below but it contains bits of other attempts to get the routine working. Any
better suggestions as to how I should be approaching this would be most
welcome.
Please don'y foget that the line "if first = last" sould be in the loop to
provide an exit from the loop.
rs1.MoveFirst
rs1.FindFirst strCriteria
first = rs1("SerialNo")
rs1.MoveLast
rs1.FindLast strCriteria
last = rs1("SerialNo")
If first = last Then Debug.Print , "Last"
Debug.Print rs1("ContractNo")
[ContractNo] = rs1("ContractNo")
strCriteria = BuildCriteria("ContractNo", dbInteger, [ContractNo])
rs1.FindFirst strCriteria
Debug.Print rs1("SerialNo")
' If Not (rs1.NoMatch) Then
Do Until rs1.EOF
rs1.FindNext strCriteria
Debug.Print rs1("SerialNo")
' Else:
' Debug.Print "no Records"
' End If
Loop
I am looking to find all the occurences in a table where one of the Fields
holds a "Serial Number" and another field holds the "Contract Number". The
Serial Numbers are unique and the Contract Numbers are the same. So, I want
to search through my Table, searching every record for a field that matches
my Contract Number Criterion and pick out the corresponding unique serial
number.
Easy, I thought. Just FindFirst Criteria, followed by a loop to FindNext
Criterion. the Loop to be terminated by an EOF.
When I did this the loop continued to run well after the last racord in the
Table had been found. (I thought thay the loop would exit after it had found
the last matching Critera)
So I came up with a solution whereby I did a Find First, store that record
in the variable "First", followed by a FindLast and store that record in the
variable "Last". I then would compare each record in the Find Next Loop with
the Variable "Last" and use that to exit wen FindNext = "Last". However, My
initial attempts gives me the results where "First" contains the first Serial
Number that matches the Contract Number, Great, Unfortunately the vatriable
Last = the same Serial Number. The loop works great and finds all of the
other serial numbers that have the same Contract Number but I have no method
of jumping out of the loop when I get to the last Matching Record.
I must be missing something,, can anyone help? I enclose my "Play" code
below but it contains bits of other attempts to get the routine working. Any
better suggestions as to how I should be approaching this would be most
welcome.
Please don'y foget that the line "if first = last" sould be in the loop to
provide an exit from the loop.
rs1.MoveFirst
rs1.FindFirst strCriteria
first = rs1("SerialNo")
rs1.MoveLast
rs1.FindLast strCriteria
last = rs1("SerialNo")
If first = last Then Debug.Print , "Last"
Debug.Print rs1("ContractNo")
[ContractNo] = rs1("ContractNo")
strCriteria = BuildCriteria("ContractNo", dbInteger, [ContractNo])
rs1.FindFirst strCriteria
Debug.Print rs1("SerialNo")
' If Not (rs1.NoMatch) Then
Do Until rs1.EOF
rs1.FindNext strCriteria
Debug.Print rs1("SerialNo")
' Else:
' Debug.Print "no Records"
' End If
Loop