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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting focus to a detail item?

Status
Not open for further replies.

JFoushee

Programmer
Oct 23, 2000
200
US
I have a form with a Search box and button at top.
The Detail section shows fields 1 and 3 over and over with the various records.

The search button has this code:

Code:
Private Sub cmdSearch_Click()

Dim rstTable1 As Recordset
Dim strSearchString As String
txtSearchString.SetFocus
strSearchString = txtSearchString.Text

Set rstTable1 = CurrentDb.OpenRecordset("Table1")

[detail field 1].SetFocus

Do While Not rstTable1.EOF
  If (InStr(rstTable1.Fields(&quot;field1&quot;).Value, strSearchString) <> 0) Then
    GoTo ending
  End If
  SendKeys &quot;{DOWN}&quot;
  If (InStr(rstTable1.Fields(&quot;field3&quot;).Value, strSearchString) <> 0) Then
    GoTo ending
  End If
  SendKeys &quot;{DOWN}&quot;
  
  rstTable1.MoveNext
Loop

ending:
rstTable1.Close
SendKeys &quot;{UP}&quot;
End Sub

It works, but WOW, I wish there were a [detail field 1](index).SetFocus command to go directly to the record, and the fact that this works under ideal conditions.

Any suggestions?
 
Look up the FindFirst method of the Recordset object. You give it search criteria, and it finds the first record that meets it.
rstTable1.FindFirst &quot;field1 like *&quot; & strSearchString & &quot;* or field3 like *&quot; & strSearchString & &quot;*&quot;
If rstTable1.NoMatch Then
' search string not found
Else
Me.Bookmark = rstTable1.Bookmark
End If
Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top