Search on typing (1 Viewer)

bodylojohn

Registered User.
Local time
Today, 07:01
Joined
Dec 28, 2005
Messages
205
Hello,

I have form containing 2 textboxes (txtsnelzoekenelementgroep and txtsnelzoekenelement)
On the mainform there also is a subform called "frmSUB_ELEMENT" wich is a datasheet.

The code below works when i put the "Call SnelZoekenElement" in the after update event of one of the two textboxes on the mainform. However when I put it in the change event it doesnt work. I want the subform to filter as I type.

Thanks in advance everyone!!!


Code:
Private Sub SnelZoekenElement()
    Dim sFilter As String
    sFilter = ""

     'Zoeken op trefwoord in elementgroep
    If Me.txtSnelZoekElementGroep.Value = "" Or IsNull(Me.txtSnelZoekElementGroep.Value) Then
      If sFilter = "" Then
          sFilter = ""
      Else
          sFilter = sFilter & ""
      End If
    Else
      If sFilter = "" Then
        sFilter = "[ElementGroep] Like '*" & Me.txtSnelZoekElementGroep.Value & "*'"
      Else
        sFilter = sFilter & " and [ElementGroep] Like '*" & Me.txtSnelZoekElementGroep.Value & "*'"
      End If
    End If
        
         'Zoeken op trefwoord in element
    If Me.txtSnelZoekElement.Value = "" Or IsNull(Me.txtSnelZoekElement.Value) Then
      If sFilter = "" Then
          sFilter = ""
      Else
          sFilter = sFilter & ""
      End If
    Else
      If sFilter = "" Then
        sFilter = "[Omschrijving] Like '*" & Me.txtSnelZoekElement.Value & "*'"
      Else
        sFilter = sFilter & " and [Omschrijving] Like '*" & Me.txtSnelZoekElement.Value & "*'"
      End If
    End If
        
If Len(sFilter) > 0 Then
  Me.frmSUB_ELEMENT.Form.Filter = sFilter
  Me.frmSUB_ELEMENT.Form.FilterOn = True
Else
  Me.frmSUB_ELEMENT.Form.Filter = ""
  Me.frmSUB_ELEMENT.Form.FilterOn = False
End If

End Sub

Private Sub txtSnelZoekElementGroep_Change()

Call SnelZoekenElement
Me.frmSUB_ELEMENT.Form.Requery

End Sub
 

RuralGuy

AWF VIP
Local time
Today, 06:01
Joined
Jul 2, 2005
Messages
13,826
If you want to use the code in the OnChange event then you need to examine the .Text property rather than the .Value property. The .Value property has been updated by the BeforeUpdate event but not at the OnChange event. The only requirement is that the control have the focus to use the .Text property, which is not a problem in your case.
 

bodylojohn

Registered User.
Local time
Today, 07:01
Joined
Dec 28, 2005
Messages
205
If you want to use the code in the OnChange event then you need to examine the .Text property rather than the .Value property. The .Value property has been updated by the BeforeUpdate event but not at the OnChange event. The only requirement is that the control have the focus to use the .Text property, which is not a problem in your case.

Thanks for your tip... but I am lost here ;-)
I tried to put the code in the before_update event of the txtboxes... And that doesnt work either.

I hope that you can help me a little bit more.

Thanks again!
 

simplyaccess

New member
Local time
Today, 14:01
Joined
Jan 8, 2010
Messages
1
Hi John

What ruralguy is saying is that if you want to filter as you type, put the code in the "on change" event, but change the code e.g. from
If Me.txtSnelZoekElementGroep.Value =
to
If Me.txtSnelZoekElementGroep.Text =

..as the .Value property doesn't get updated until you've finished typing and moved the focus to somewhere else on the form, whereas the .text property updates as you type.

Hope that helps.

Mark
www.simplyaccess.net
 

bodylojohn

Registered User.
Local time
Today, 07:01
Joined
Dec 28, 2005
Messages
205
Hi John

What ruralguy is saying is that if you want to filter as you type, put the code in the "on change" event, but change the code e.g. from
If Me.txtSnelZoekElementGroep.Value =
to
If Me.txtSnelZoekElementGroep.Text =

..as the .Value property doesn't get updated until you've finished typing and moved the focus to somewhere else on the form, whereas the .text property updates as you type.

Hope that helps.

Mark
www.simplyaccess.net

I am an idiot!!!
I was looking at the wrong code..

It works great!!!!

Thank you very much guys!!!!!
 

Users who are viewing this thread

Top Bottom