Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 457
  • Last Modified:

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

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
TSUS MIS
Asked:
TSUS MIS
  • 2
1 Solution
 
IrogSintaCommented:
Try this:
DoCmd.OpenForm "frmInventory", , , SearchField & " Like  '*" & strCriteria & "*'"

Open in new window

0
 
TSUS MISAuthor Commented:
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
 
IrogSintaCommented:
Quite welcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now