How to stop somebody modify the searsh field on a form

V

Veli Izzet

Hi All,

I want to be able to search by a field on a form, but I do not want
somebody to change it.

If I use enabled "No", and Locked "Yes" , I cannot do searches too.

Is there any way out?
 
A

Allen Browne

Instead of trying to use one text box for 2 purposes (data entry and
searches), provide 2 different controls: one where the user enters the data
(bound to the field), and a different one where the user enters search data
(unbound).
 
A

Allen Browne

If there is just one text box to search from, use its AfterUpdate event
procedure to set the Filter of the form (if there are multiple possible
matches), or to FindFirst in the RecordsetClone of the form (if there is
just one match.)

This example shows how to set the form's filter:
Private Sub txtFindSurname_AfterUpdate()
Dim strWhere As String
If Not IsNull(Me.txtFindSurname) Then
If Me.Dirty Then Me.Dirty = False 'Save first.
strWhere = "[Surname] = """ & Me.txtFindSurname & """"
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub

For an example of how to FindFirst, see the code in this example:
http://allenbrowne.com/ser-03.html
Although the example talks about a combo box, the code is the same for a
text box.
 
Top