PDA

View Full Version : [SOLVED:] Filter problem



TonC
02-09-2016, 01:48 AM
Hello,:(
I've got a table named "tblRelaties". In that table there two fields:

rel_id = autonumbering and Primary key
Relatienaam = just text

When I want to filter on a relationname (Relatienaam), in some cases the form shows me 3 or more relations, while I'am looking for just one relation.
I presume it has somthing to do with the autonumbering, because there is a relation with the number 7, but also relations with the numbers 87 and 27.

In my query, in the field named "Relatie" there is this criteria;
Like [Forms]![frmMagazijn1]![cmbRelatie]

The criteria
Like [Forms]![frmMagazijn1]![cmbRelatie] & "*" did not work
The criteria
Like "*" & [Forms]![frmMagazijn1]![cmbRelatie] & "*" did not work



And my VBA code is: (a combobox on my mainform named "cmdRelatie")

Private Sub cmbRelatie_AfterUpdate()
Me.subfrmMagazijn1.Requery
End Sub

What goes wrong? Can someone help me?
If you need further information, please contact me.
Many thanks in anticipation

ranman256
02-09-2016, 06:36 AM
show all records in the form,
filter using
me.filter="[field] like *" & txtBox & "*"
me.filteron = true

TonC
02-09-2016, 11:08 AM
Hello ranman256,
I tried

Private Sub cmbRelatie_AfterUpdate()
me.filter="[Relatie] like *" & cmdRelatie & "*"

me.filteron = true

Sorry, still the same problem.

TonC
02-17-2016, 02:16 PM
Hello ranman, sorry for my late reaction, but I think I solved the problem.



Private Sub btnFilter_Click()
Dim db As DAO.Database

Dim strWhere As String 'The criteria string.
Dim lngLen As Long 'Length of the criteria string to append to.

If Not IsNull(Me.cmbRelatie) Then
strWhere = strWhere & "([Relatie]=" & Me.cmbRelatie & ") AND "
End If

lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
msgbox "No criteria", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the " AND " at the end.
strWhere = Left$(strWhere, lngLen)
'For debugging, remove the leading quote on the next line. Prints to Immediate Window (Ctrl+G).
Debug.Print strWhere

Me.subfrmMagazijn1.Form.Filter = strWhere
Me.subfrmMagazijn1.Form.FilterOn = True

End If

End Sub



The above code works fine for me.
But anyway, much thanks for your help