Record with blank field not visible after using filter (1 Viewer)

joshi868b

Registered User.
Local time
Today, 19:22
Joined
Jul 26, 2016
Messages
10
i have a form with a subform and few combo box to use as a filter the data. when there is a blank field in the table it is not shown my coding for the filter is
[

Function searchcriteria()
Dim device, vlan As String
Dim task, strciteria As String


If IsNull(Me.cbodevice) Then
device = "[DEVICE NAME] like '*'"
Else
device = "[DEVICE NAME]= '" & Me.cbodevice & "'"
End If


If IsNull(Me.cbovlan) Then
vlan = "[VLAN ID] like '*'"
Else
vlan = "[VLAN ID]= '" & Me.cbovlan & "'"
End If
strcriteria = device & "And" & vlan
task = "select * from L2PORTDETAILS where " & strcriteria
Me.L2PORTDETAILS_subform.Form.RecordSource = task
Me.L2PORTDETAILS_subform.Form.Requery


End Function]
 

TJPoorman

Registered User.
Local time
Today, 07:52
Joined
Jul 23, 2013
Messages
402
The problem is if your field is NULL and not "".
Instead test to see if your search field is NOT null, then build the filter.
You'll also run into problems if the user only selects one or no options. You're building the WHERE statement and it may or may not pass arguments.

Code:
Function searchcriteria()
Dim device, vlan As String
Dim task, strciteria As String

If Nz(Me.cbodevice, "") <> "" Then
    device = "[DEVICE NAME]= '" & Me.cbodevice & "' AND "
End If

If Nz(Me.cbovlan, "") <> "" Then
    vlan = "[VLAN ID]= '" & Me.cbovlan & "' AND "
End If

If Len(strcriteria) > 0 Then
    strcriteria = " WHERE " & Left(strcriteria, Len(strcriteria) - 5)
End If

task = "select * from L2PORTDETAILS" & strcriteria
Me.L2PORTDETAILS_subform.Form.RecordSource = task
Me.L2PORTDETAILS_subform.Form.Requery
End Function
 

joshi868b

Registered User.
Local time
Today, 19:22
Joined
Jul 26, 2016
Messages
10
dear,
i used the same code it is not working
it is not even filtering kindly help me
thanking you again
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:52
Joined
May 7, 2009
Messages
19,245
where did you put your function? should be on the main form.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:52
Joined
May 7, 2009
Messages
19,245
If IsNull(Me.cbodevice) Then
device = "TRUE=TRUE"
Else
device = "[DEVICE NAME]= '" & Me.cbodevice & "'"
End If


If IsNull(Me.cbovlan) Then
vlan = "TRUE=TRUE"
Else
vlan = "[VLAN ID]= '" & Me.cbovlan & "'"
End If
strcriteria = device & " And " & vlan
task = "select * from L2PORTDETAILS where " & strcriteria
Me.L2PORTDETAILS_subform.Form.RecordSource = task
' no need to requery when you change recordsource
' it is automatic
'Me.L2PORTDETAILS_subform.Form.Requery
 

Users who are viewing this thread

Top Bottom