Search button on a bound Form on a specific field

mooredk

Registered User.
Local time
Today, 10:53
Joined
Mar 20, 2013
Messages
18
So I'm not new to Access but I am to 2010. It has been a bit "challenging". Here's my first question:

1.) I'm trying to search on a field by using a command button. I basically want to click the button and the following message pops up: Enter MRN.
2.) When the MRN is entered, I would like the form to filter on all records that have this MRN.
3.) In old versions of Access, I would create a Macro for this and then call the Macro in the form.
4.) I've tried the FindRecord action in the Macro but it does not work. I actually came across several actions that don't seem to be working properly (getting error messages).
5.) In my head, this should be one of the EASIEST things to do. I've done this before in several different databases. I will admit it has been a few years since I have used Access for this (ie. building forms, macros etc.). I've primarly used it to pull in a data set and then run some queries to get the data I need quickly versus using Excel.

Any suggestions/help is appreciated. All of the stuff I have been reading on (bought the huge book Access 2010 Programmers Reference and then on some forums) seem a little more complex than it needs to be. But if it what works I'm all for it.
 
In the on click event of you button try

Code:
Dim Vl as string (or integer or long or whatever the MRN type is
 
Vl=inputbox("Enter MRN")
if Vl<>"" then ' for text or Vl<>0 for number
    me.filter="[MRN]='" & Vl & "'" ' for text or ="[MRN]=" & Vl  for number
    me.filteron=true
End if

I've assumed MRN is a string but provided the numeric equivalent if it is a number
 
Thank you , thank you, thank you CJ London! It worked. I feel so stupid! I have been reading books and looking at forums..I'm sure you'll see many more posts from me LOL!! Thanks so much again!
 
OK..So what code do I use to clear the filter and return form as it is when I open it? I used me.filteron = false; me.requery; me.refresh...all of this code was used on a new command button to basically clear the filter. I know I'm missing something. I'm so frustrated!
 
OK..So what code do I use to clear the filter and return form as it is when I open it? I used me.filteron = false; me.requery; me.refresh...all of this code was used on a new command button to basically clear the filter. I know I'm missing something. I'm so frustrated!
Me.Filter = vbNullstring
Me.FilterOn = False
 
Oh my gosh!! I have searched forums and read this book. I thought me.filteron = false would work...I would have never figure of me.filter = vbnullstring! I tried some other code with me.filter but not that! Thanks so much. Frustrating not figuring out on my own what seems to be the simplest things!! Thanks again!
 

Users who are viewing this thread

Back
Top Bottom