Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find Confusion

Status
Not open for further replies.

georgp

Technical User
Mar 28, 2002
96
0
0
US
Hi,

I have behind butons code to "find" certain recordsets, the code is almost the same for find, findfirst, findnext, findlast. To make things easier to explain, I copy the 'findlast' code and describe (one of) the problem(s):

Private Sub btn_LastRec_Click()
'Purpose: Find the last matching recordset
'sFind can be string. number,or date expression

Const cstrProc As String = "btn_LastRec_Click"
On Error GoTo btn_LastRec_Click_Err

Dim rst As Recordset
Dim Oldbook as Integer

Set rst = Me.RecordsetClone

MsgBox rst.AbsolutePosition (1. MsgBox, this is added for examination purposes only)

rst.FindLast sFind
Me.Bookmark = rst.Bookmark

MsgBox rst.AbsolutePosition (2. MsgBox, this is added for examination purposes only)

'(3rd MsgBox - should fire when last match)
If OldBook = rst.AbsolutePosition Then
MsgBox "You are already on the last recordset matching the criteria '" & sFind & "'." & Space(12), vbInformation, gsApplName
GoTo btn_LastRec_Click_Exit
End If
OldBook = rst.AbsolutePosition

Set rst = Nothing

btn_LastRec_Click_Exit:
Exit Sub

btn_LastRec_Click_Err:
Call bss_ErrMsgStd(Me.Name & "." & cstrProc, Err.Number, Err.Description, True)
Resume btn_LastRec_Click_Exit

End Sub

Let's presume rst.Absoluteposition is 799 for this last matching record.
Now what happens, when I start e.g.from record 240:
If I fire the button, the last matching recordset is found (which is ok). The msgboxes describing the position indicate following positions:
1. MsgBox: 240
2. Msgbox: 798
Should that not be 799? 798 is a no match.
I press the button again and now
1. MsgBox: 798
2. MsgBox: 799
Acutally, expectation is that the third msgbox should show, but it does not. No visible change; the user would have the impression that nothing happended.
Now I press the button again with the result:
1. Msgbox: 799
2. MsgBox: 799
3. Msgbox shows.
Can somebody tell, what I am doing wrong? Thanks.
georgp
 
I'd like to add, if somebody has a working code example for these find, findfirst, etc, I would appreciate the posting of it.
Thanks, georgp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top