Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-01-25
3
Medium Priority
?
454 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 2000 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

722 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