Solved

Using a variable string for fieldname in the Where clause of a DoCmd.Open form statement

Posted on 2013-01-25
3
452 Views
Last Modified: 2013-01-25
Hello again,
I am working on form with a combo box. The combo box contains the field names in which the user would want to search.

I have the code passing the correct data, but I can't seem to get the syntax of the WHERE clause in the DoCmd.OpenForm correct, when the the string is at the beginning of the clause:

Private Sub SearchButton_Click()

Dim strCriteria As String
strCriteria = InputBox("Enter Equipment Name")

Dim SearchField As String
SearchField = Me!cmbFieldName

DoCmd.OpenForm "frmInventory", , , "SearchField Like  '*" & strCriteria & "*'"

End Sub

Open in new window


Thanks in advance.
0
Comment
Question by:Clinton Smith
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
IrogSinta earned 500 total points
ID: 38821227
Try this:
DoCmd.OpenForm "frmInventory", , , SearchField & " Like  '*" & strCriteria & "*'"

Open in new window

0
 

Author Closing Comment

by:Clinton Smith
ID: 38821236
After hours of trying to fix this on my own, and many variations of placement, this was the correct answer.
Thanks so much again, Ron.
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38821238
Quite welcome.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month11 days, 15 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question