title: How can I create button to search database column names in MS Access?
body: <p>I am trying to create a button in MS Access 2013 that allows a user to search a database for a column containing input text. I was able to find the search code in this post ( <a href="https://stackoverflow.com/questions/10405237/find-a-table-when-you-know-the-name-of-a-column/10405808#10405808">Find a table when you know the name of a column?</a> ) but I can't figure out how to bind it to a button. Also when I run the search function from main it doesn't give any output. The only way I can get the search function to work is to hard code the search string into the function.</p>
  
  <pre><code>Sub Main()
      Dim inStr As String
  
      ListTablesWithColumnNamesContaining (InputBox("Name contains", "Search"))
  End Sub
  
  Public Sub ListTablesWithColumnNamesContaining(ByVal pText As String)
      Dim db As DAO.Database
      Dim tdf As DAO.TableDef
      Dim fld As DAO.Field
      Set db = CurrentDb
      For Each tdf In db.TableDefs
          For Each fld In tdf.Fields
              If InStr(1, fld.Name, "pText", vbTextCompare) &gt; 0 Then
                  Debug.Print tdf.Name &amp; ":", fld.Name
              End If
          Next fld
      Next tdf
      Set fld = Nothing
      Set tdf = Nothing
      Set db = Nothing
  End Sub
  </code></pre>