Search in form

  • Thread starter Thread starter Lodewijk Olthof
  • Start date Start date
L

Lodewijk Olthof

I have a form with the field txtName and a subform with members.
In txtName I can put in a name and then I want to got to the specific name
in the subform. This has to be done while editing txtName.

For instance in subform are the following names:
Aaa; Aab; Aac; Aba; Abb; Abc; Aca

When typing A in txtName, the row Aaa is selected;
when typing Ab; the row Aba is selected.

What is the code for after updating txtName?
 
Hi Lodewijk

Something like this attached to the textbox's Change event should do the
trick:

Private Sub txtName_Change()
Dim f as Form
Set f = Me![name of subform control].Form
With f.RecordsetClone
.FindFirst "[Name field] like """ & txtName.Text & "*"""
if .nomatch then
MsgBox "Not found"
Else
f.Bookmark = .Bookmark
End If
End With
Set f = Nothing
End Sub

Note that the Change event is raised every time the text in the textbox is
changed, so you must use the Text property, not the Value property, which
only changes when the textbox is updated.
 
Back
Top