formerTexan
Programmer
Hi,
The following procedure is hihglight a user entered string within the text on a selected control. It is placed on the form's OnCurrent event.
No problems until I programmatically switch the form's recordsource. Then the FOR EACH CTL...NEXT loop gets stuck in the loop.
There are about a dozen controls in the form header, but the code repeatedly cycles through the entire collection.
Question: Doesn't anyone see a reason why ther shouldn't be just one circuit of the loop?
Thank in advance,
Bill
If Len(Me.txtFind.Value) > 0 Then ' if user has entered a search value
strSearch = Me.txtFind.Value ' search for this string
While blnFlag = False
'HERE IS WHERE THE LOOP STICKS
For Each ctl In Me.FormHeader.Controls
strTag = ctl.Tag 'set focus of search on this control
If strTag = "Search" Then
If Len(ctl.Value) > 0 Then
strMatch = ctl.Value
intWhere = InStr(strMatch, strSearch) 'Find string in text and return its position to intWhere.
If intWhere > 0 Then 'returns 0 if no match
' If found.
blnFlag = True
ctl.SetFocus
ctl.SelStart = intWhere - 1 'to adjust for zero based integer
ctl.SelLength = Len(strSearch)
End If
End If
End If
Next ctl
Wend
End If
The following procedure is hihglight a user entered string within the text on a selected control. It is placed on the form's OnCurrent event.
No problems until I programmatically switch the form's recordsource. Then the FOR EACH CTL...NEXT loop gets stuck in the loop.
There are about a dozen controls in the form header, but the code repeatedly cycles through the entire collection.
Question: Doesn't anyone see a reason why ther shouldn't be just one circuit of the loop?
Thank in advance,
Bill
If Len(Me.txtFind.Value) > 0 Then ' if user has entered a search value
strSearch = Me.txtFind.Value ' search for this string
While blnFlag = False
'HERE IS WHERE THE LOOP STICKS
For Each ctl In Me.FormHeader.Controls
strTag = ctl.Tag 'set focus of search on this control
If strTag = "Search" Then
If Len(ctl.Value) > 0 Then
strMatch = ctl.Value
intWhere = InStr(strMatch, strSearch) 'Find string in text and return its position to intWhere.
If intWhere > 0 Then 'returns 0 if no match
' If found.
blnFlag = True
ctl.SetFocus
ctl.SelStart = intWhere - 1 'to adjust for zero based integer
ctl.SelLength = Len(strSearch)
End If
End If
End If
Next ctl
Wend
End If