Apply Filter Command Button (1 Viewer)

falcondeer

Registered User.
Local time
Today, 15:30
Joined
May 12, 2013
Messages
101
Hi

Can somebody help me please

I added a command button to search for a specific record using ApplyFilter. It is working fine but I discovered when I click on the search command button when the text box is empty, it gives me a specific record.

why I don't know.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:30
Joined
May 7, 2009
Messages
19,246
what is your code on applying the filter?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:30
Joined
May 7, 2009
Messages
19,246
you need to pass to Nz() function your textbox:

[P_MRN] Like "*" & Nz([Forms]![tblPatient]![TextSearch], "$@$@$@$@$") & "*"
 

theDBguy

I’m here to help
Staff member
Local time
Today, 15:30
Joined
Oct 29, 2018
Messages
21,555
Hi

Can somebody help me please

I added a command button to search for a specific record using ApplyFilter. It is working fine but I discovered when I click on the search command button when the text box is empty, it gives me a specific record.

why I don't know.
Why would you click on the search button when the box is empty? What would you like to happen then?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:30
Joined
May 7, 2009
Messages
19,246
can you upload a striped version of your db.
 

falcondeer

Registered User.
Local time
Today, 15:30
Joined
May 12, 2013
Messages
101
It is confusing to the user I guess.
and normally, nothing should appear when you search empty.

Second question if you don't mind,

What if I want a pop up message to appear if the patient is not found saying "Sorry the patient is not found".

Thanks
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:30
Joined
May 7, 2009
Messages
19,246
check first if the [Forms]![tblPatient]![TextSearch] is empty.
if empty just go to New record (to show blank).
otherwise display the filter:

Code:
If Len(Trim$([Forms]![tblPatient]![TextSearch] & "")) = 0 Then
    'goto new record
    docmd.GoToRecord,,acNewRec
Else
    'check if Any record will return
    If DCount("1", "yourTable", "[P_MRN] Like *" & [Forms]![tblPatient]![TextSearch] & "*") > 0 Then
        'apply the filter
        docmd.ApplyFilter , "[P_MRN] Like *" & [Forms]![tblPatient]![TextSearch] & "*"
    Else
        Msgbox "Sorry patient not found."
    End If
END IF
 

falcondeer

Registered User.
Local time
Today, 15:30
Joined
May 12, 2013
Messages
101
check first if the [Forms]![tblPatient]![TextSearch] is empty.
if empty just go to New record (to show blank).
otherwise display the filter:

Code:
If Len(Trim$([Forms]![tblPatient]![TextSearch] & "")) = 0 Then
    'goto new record
    docmd.GoToRecord,,acNewRec
Else
    'check if Any record will return
    If DCount("1", "yourTable", "[P_MRN] Like *" & [Forms]![tblPatient]![TextSearch] & "*") > 0 Then
        'apply the filter
        docmd.ApplyFilter , "[P_MRN] Like *" & [Forms]![tblPatient]![TextSearch] & "*"
    Else
        Msgbox "Sorry patient not found."
    End If
END IF
How can I enter this code while I am using the Macro builder not the Code Builder !!!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:30
Joined
May 7, 2009
Messages
19,246
here is a sample with Macro.
 

Attachments

  • Database1.zip
    34.8 KB · Views: 116

Users who are viewing this thread

Top Bottom