Solved

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

Posted on 2013-01-25
3
447 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:TS Tech USA
  • 2
3 Comments
 
LVL 29

Accepted Solution

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

Open in new window

0
 

Author Closing Comment

by:TS Tech USA
Comment Utility
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
Comment Utility
Quite welcome.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
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.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now