By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,389 Members | 2,065 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,389 IT Pros & Developers. It's quick & easy.

VBA Search Bar - Enter Parameter Value

P: 8
I am very new to Access and am trying to create a simple search bar. I know almost nothing about coding; everything I have is an amalgam of things I've been able to find online.
That being said, I have a code for a partially working search bar that works off of the stLinkCriteria function. I want to be able to enter a specific number OR a general text into an unbound form that will bring up the searched records. The number part works perfectly; the problem is with the general text. It brings up the Enter Parameter Value message box, but when I click OK it goes to the record being searched. How do I get rid of the pop up?
Expand|Select|Wrap|Line Numbers
  1. Private Sub Search_Click()
  2. Dim stLinkCriteria As String
  3.     stLinkCriteria = CStr("[ID]=" & Me![txtSearch]) & " Or [iName]like'*" & Me![txtSearch] & "*'"
  4.     DoCmd.OpenForm "Form1", , , stLinkCriteria
  5. End Sub
Any information would be really helpful. Thanks!
Jun 7 '17 #1

✓ answered by NeoPa

It seems what you really want is some type of form filtering. Cascaded Form Filtering may help. In there are links to other articles if that doesn't perfectly match your requirements.

PS. Searching/filtering on multiple words is certainly possible. If you find after reading the linked articles that you need further help on that then please post back with clear and specific details of what you require.

Share this Question
Share on Google+
4 Replies


P: 8
**Update**
I tooled around a little and found that the Text search doesn't work with two words. It will pop up saying there's a Syntax error with a missing operator.
Jun 7 '17 #2

NeoPa
Expert Mod 15k+
P: 31,494
It seems what you really want is some type of form filtering. Cascaded Form Filtering may help. In there are links to other articles if that doesn't perfectly match your requirements.

PS. Searching/filtering on multiple words is certainly possible. If you find after reading the linked articles that you need further help on that then please post back with clear and specific details of what you require.
Jun 7 '17 #3

P: 8
Yes and no. I am trying to open a form based on a general search from another form. The id number can be exact but I want the name to be able to be searched broadly. I have two separate codes that work perfectly. I want to combine them somehow.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Search_Click()
  2. Dim stlinkcriteria As String
  3. stlinkcriteria = "[ID]=" & Me![txtSearch]
  4. DoCmd.OpenForm "Form1", , , stlinkcriteria
  5. End Sub
  6.  
  7. Private Sub Search_Click()
  8. Dim stlinkcriteria As String
  9. stlinkcriteria = "[iName]like'*" & Me![txtSearch] & "*'"
  10. DoCmd.OpenForm "Form1", , , stlinkcriteria
  11. End Sub
Jun 7 '17 #4

NeoPa
Expert Mod 15k+
P: 31,494
When you say you want to combine them somehow, what do you actually mean?

There are examples in the linked article that allow one or other or both types of filtering as well as handling strings and numbers. I can't imagine what you'd need more than that, but please explain clearly what it is if you still do.
Jun 7 '17 #5

Post your reply

Sign in to post your reply or Sign up for a free account.