[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 456
  • 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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

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