Code for button to execute a filter on a form

R

Rod ElEd

I would like a command button on a form that will ask
what word(s) to search for in a memo field. This is a memo fields with info
on books. The name of the field is "notes". I have scanned posts
in this group and discovered the following string that
seems to accomplish part of this task:
Like "*" & [What word?] & "*"
I would like to make this very simple for users; they click the button,
answer the prompt questions, hit "enter" and the search executes.
What else do I need in the command?
Where do I put the code after I create the button?
Thanks in advance for any help.
Rod
 
J

Jeff L

Dim MySearchTerm as String
MySearchTerm = Inputbox "Enter a word to search for"
Me.Filter = "Notes Like '*" & MySearchTerm & "*'"
Me.FilterOn = True

You could also have a field on your form that the user enters their
search term.
You will probably want to include a way to "turn off" the filter.

Me.FilterOn = False

Hope that helps!
 
R

Rod ElEd

Thanks.
Now, this probably sounds quite stupid, but where do I put this script?
Also, how will it know which field in which to search?

Jeff L said:
Dim MySearchTerm as String
MySearchTerm = Inputbox "Enter a word to search for"
Me.Filter = "Notes Like '*" & MySearchTerm & "*'"
Me.FilterOn = True

You could also have a field on your form that the user enters their
search term.
You will probably want to include a way to "turn off" the filter.

Me.FilterOn = False

Hope that helps!


Rod said:
I would like a command button on a form that will ask
what word(s) to search for in a memo field. This is a memo fields with info
on books. The name of the field is "notes". I have scanned posts
in this group and discovered the following string that
seems to accomplish part of this task:
Like "*" & [What word?] & "*"
I would like to make this very simple for users; they click the button,
answer the prompt questions, hit "enter" and the search executes.
What else do I need in the command?
Where do I put the code after I create the button?
Thanks in advance for any help.
Rod
 
R

Rod ElEd

I inserted the 4 lines of code you gave and ran it. It returns an error
message with: MySearchTerm = Inputbox "Enter a word to search for"
highlighted as the difficulty. Ideas?

Jeff L said:
Dim MySearchTerm as String
MySearchTerm = Inputbox "Enter a word to search for"
Me.Filter = "Notes Like '*" & MySearchTerm & "*'"
Me.FilterOn = True

You could also have a field on your form that the user enters their
search term.
You will probably want to include a way to "turn off" the filter.

Me.FilterOn = False

Hope that helps!


Rod said:
I would like a command button on a form that will ask
what word(s) to search for in a memo field. This is a memo fields with info
on books. The name of the field is "notes". I have scanned posts
in this group and discovered the following string that
seems to accomplish part of this task:
Like "*" & [What word?] & "*"
I would like to make this very simple for users; they click the button,
answer the prompt questions, hit "enter" and the search executes.
What else do I need in the command?
Where do I put the code after I create the button?
Thanks in advance for any help.
Rod
 
J

Jeff L

MySearchTerm = Inputbox("Enter a word to search for")



Rod said:
I inserted the 4 lines of code you gave and ran it. It returns an error
message with: MySearchTerm = Inputbox "Enter a word to search for"
highlighted as the difficulty. Ideas?

Jeff L said:
Dim MySearchTerm as String
MySearchTerm = Inputbox "Enter a word to search for"
Me.Filter = "Notes Like '*" & MySearchTerm & "*'"
Me.FilterOn = True

You could also have a field on your form that the user enters their
search term.
You will probably want to include a way to "turn off" the filter.

Me.FilterOn = False

Hope that helps!


Rod said:
I would like a command button on a form that will ask
what word(s) to search for in a memo field. This is a memo fields with info
on books. The name of the field is "notes". I have scanned posts
in this group and discovered the following string that
seems to accomplish part of this task:
Like "*" & [What word?] & "*"
I would like to make this very simple for users; they click the button,
answer the prompt questions, hit "enter" and the search executes.
What else do I need in the command?
Where do I put the code after I create the button?
Thanks in advance for any help.
Rod
 
J

Jeff L

Put it anywhere, behind a button or a checkbox, whereever you see fit.
You said you wanted to search the Notes field right? That's what the
Filter does.


Rod said:
Thanks.
Now, this probably sounds quite stupid, but where do I put this script?
Also, how will it know which field in which to search?

Jeff L said:
Dim MySearchTerm as String
MySearchTerm = Inputbox "Enter a word to search for"
Me.Filter = "Notes Like '*" & MySearchTerm & "*'"
Me.FilterOn = True

You could also have a field on your form that the user enters their
search term.
You will probably want to include a way to "turn off" the filter.

Me.FilterOn = False

Hope that helps!


Rod said:
I would like a command button on a form that will ask
what word(s) to search for in a memo field. This is a memo fields with info
on books. The name of the field is "notes". I have scanned posts
in this group and discovered the following string that
seems to accomplish part of this task:
Like "*" & [What word?] & "*"
I would like to make this very simple for users; they click the button,
answer the prompt questions, hit "enter" and the search executes.
What else do I need in the command?
Where do I put the code after I create the button?
Thanks in advance for any help.
Rod
 
R

Rod ElEd

We are closer!!! This works to provide 1 record that matches. How can I get
it to show ALL of the records that match?

Jeff L said:
MySearchTerm = Inputbox("Enter a word to search for")



Rod said:
I inserted the 4 lines of code you gave and ran it. It returns an error
message with: MySearchTerm = Inputbox "Enter a word to search for"
highlighted as the difficulty. Ideas?

Jeff L said:
Dim MySearchTerm as String
MySearchTerm = Inputbox "Enter a word to search for"
Me.Filter = "Notes Like '*" & MySearchTerm & "*'"
Me.FilterOn = True

You could also have a field on your form that the user enters their
search term.
You will probably want to include a way to "turn off" the filter.

Me.FilterOn = False

Hope that helps!


Rod ElEd wrote:
I would like a command button on a form that will ask
what word(s) to search for in a memo field. This is a memo fields with info
on books. The name of the field is "notes". I have scanned posts
in this group and discovered the following string that
seems to accomplish part of this task:
Like "*" & [What word?] & "*"
I would like to make this very simple for users; they click the button,
answer the prompt questions, hit "enter" and the search executes.
What else do I need in the command?
Where do I put the code after I create the button?
Thanks in advance for any help.
Rod
 
R

Rod ElEd

Hey, wait, Jeff. I got it. Not sure what I had done incorrectly, but it now
works perfectly. Thanks so much for being patient with a newbie.

Jeff L said:
MySearchTerm = Inputbox("Enter a word to search for")



Rod said:
I inserted the 4 lines of code you gave and ran it. It returns an error
message with: MySearchTerm = Inputbox "Enter a word to search for"
highlighted as the difficulty. Ideas?

Jeff L said:
Dim MySearchTerm as String
MySearchTerm = Inputbox "Enter a word to search for"
Me.Filter = "Notes Like '*" & MySearchTerm & "*'"
Me.FilterOn = True

You could also have a field on your form that the user enters their
search term.
You will probably want to include a way to "turn off" the filter.

Me.FilterOn = False

Hope that helps!


Rod ElEd wrote:
I would like a command button on a form that will ask
what word(s) to search for in a memo field. This is a memo fields with info
on books. The name of the field is "notes". I have scanned posts
in this group and discovered the following string that
seems to accomplish part of this task:
Like "*" & [What word?] & "*"
I would like to make this very simple for users; they click the button,
answer the prompt questions, hit "enter" and the search executes.
What else do I need in the command?
Where do I put the code after I create the button?
Thanks in advance for any help.
Rod
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top