ACC95: FindNext Does Not Advance to Next Record to SearchID: Q150665
|
When the FindNext macro action is run from a command button on a form to
find the next instance of the search criteria specified by the previous
FindRecord action, the first instance is found repeatedly. The FindNext
macro action fails to advance to the next record to find the next instance
of the search criteria.
NOTE: The same behavior can be demonstrated using the FindRecord macro
action with the FindFirst argument set to No.
Microsoft Access for Windows 95 and Microsoft Access version 2.0 behave
differently in regard to where the FindNext macro action begins the
search for the next instance of the search criteria.
The FindNext action in Microsoft Access version 2.0 always begins
searching starting with the next record in the recordset. In Microsoft
Access for Windows 95, if the currently selected text is the same as the
search text at the time the FindNext macro action is invoked, the search
begins immediately following the selection in the same field as the
selection, and in the same record. Otherwise, it begins searching at the
start of the current record.
The advantage to the Microsoft Access for Windows 95 behavior is that
you can repeatedly find multiple instances of the same search criteria
that might appear in a single record. The FindNext macro action in
Microsoft Access version 2.0 is limited to finding only the first instance
of the search criteria in a record, regardless of other instances of the
same search criteria in the record.
The problem occurs in Microsoft Access for Windows 95 when you push a
custom Find Next command button on a form. When this happens, focus
moves from the current control to the button. If text is selected in the
current control, it will not remain selected when the focus moves to the
button. The FindNext action will then begin searching from the start of the
record because the current selection is no recognized. The first
instance of the search criteria will be found repeatedly in the same
record.
Use one of the following techniques to work around this behavior:
Macro Name Macro Action
--------------------------
Company GoToControl
FindRecord
Company Actions
--------------------------------------------
GoToControl:
ControlName: CompanyName
FindRecord:
Find What: =[Forms]![Customers]![txtFind]
Match: Any Part of Field
Match Case: No
Search: All
Search As Formatted: No
Only Current Field: Yes
Find First: Yes
Macro Name Macro Action
---------------------------
NextCompany GoToControl
FindNext
NextCompany Actions
---------------------------
GoToControl:
ControlName: CompanyName
Name: txtFind
ControlSource: <leave empty>
DefaultValue: "a"
Name: FindCompany
Caption: Find Company
OnClick: Find.Company
Name: FindNextCompany
Caption: Find Next Company
OnClick: Find.NextCompany
Macro Name Macro Action
---------------------------
{F3} FindNext
Name: NewFindCompany
Caption: New Find Company
Private Sub NewFindCompany_Click()
Me![CompanyName].SetFocus
DoCmd.FindRecord Me![txtFind], acAnywhere
RecordFind
End Sub
Name: NewFindNextCompany
Caption: New Find Next Company
Private Sub NewFindNextCompany_Click()
RestoreFind
DoCmd.FindNext
RecordFind
End Sub
Dim FoundControl As Control
Dim FoundControlSelStart As Integer
Dim FoundControlSelLength As Integer
Sub RestoreFind()
FoundControl.SetFocus
FoundControl.SelStart = FoundControlSelStart
FoundControl.SelLength = FoundControlSelLength
End Sub
Sub RecordFind()
Set FoundControl = Me.ActiveControl
FoundControlSelStart = Me.ActiveControl.SelStart
FoundControlSelLength = Me.ActiveControl.SelLength
End Sub
Keywords : kbusage McrArg
Version : 7.0
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: April 22, 1999