G
Guest
How do I design a form that prompts a user to enter info to find a specific
record in a table?
record in a table?
Allen Browne said:Add an unbound text box to the form. Use the AfterUpdate event procedure of
this control to find the matching record.
The code will be something like this:
Sub txtFind_AfterUpdate ()
Dim rs As DAO.Recordset
If Not IsNull(Me.txtFind) Then
'Save before move.
If Me.Dirty Then
Me.Dirty = False
End If
'Search in the clone set.
Set rs = Me.RecordsetClone
rs.FindFirst "[CustomerID] = " & Me.txtFind
If rs.NoMatch Then
MsgBox "Not found: filtered?"
Else
'Display the found record in the form.
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing
End If
End Sub
Note: If the CustomerID field is a Text field (not a Number field), you need
extra quotes:
rs.FindFirst "[CustomerID] = """ & Me.txtFind & """"
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
Andre said:How do I design a form that prompts a user to enter info to find a
specific
record in a table?
kenjikimura23 said:I did learned from this answer you gave but I just wondering about the
dirty
whats the use of that anyway and what does the result of that. I hope you
could ellaborate it much more so I would understand it better.
Thanks Allen.
Allen Browne said:Add an unbound text box to the form. Use the AfterUpdate event procedure
of
this control to find the matching record.
The code will be something like this:
Sub txtFind_AfterUpdate ()
Dim rs As DAO.Recordset
If Not IsNull(Me.txtFind) Then
'Save before move.
If Me.Dirty Then
Me.Dirty = False
End If
'Search in the clone set.
Set rs = Me.RecordsetClone
rs.FindFirst "[CustomerID] = " & Me.txtFind
If rs.NoMatch Then
MsgBox "Not found: filtered?"
Else
'Display the found record in the form.
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing
End If
End Sub
Note: If the CustomerID field is a Text field (not a Number field), you
need
extra quotes:
rs.FindFirst "[CustomerID] = """ & Me.txtFind & """"
Andre said:How do I design a form that prompts a user to enter info to find a
specific
record in a table?