• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 357
  • Last Modified:

Access 2007: Add Filter to VBA Script controlling export of data to MS Word?

Hi everyone, I have a VBA script that experts here have crafted over time which exports selected fields (as captions) to a Microsoft Word document.  I know how to create a 'filter' in a SQL query with where clauses, but I would like to implement a method to do this on the form.  I wanted something similar to: http://allenbrowne.com/AppSearchHighlight.html (the highlighting is optional but I liked the search box with combo box populated by relevant fields).  I've tried to modify this code with my form 'MakeWordTable' but it doesn't seem to be working.  I've attached the database here if anyone can take a look at what I'm doing and try to help I'd very much appreciate it.  As of now I keep getting errors saying that it can't find the field I've inputted into the combo box.   If users think I am barking up the wrong tree with this approach let me know that as well and please offer another suggestion.  Even a simple solution would be excellent.  My ultimate goal is to perhaps have two or three methods for the user to filter the data on the MakeWordTable form.  

I'm attaching the file here if anyone is interested in looking.

Thank you so much,
  • 2
  • 2
1 Solution
Nico BontenbalCommented:
In the Command2_Click after the line:
strSql = "select " & fieldlist & " from qryAll"
I've added these lines:
If Not IsNull(Me.cboField) Then
    strSql = strSql & " WHERE " & Me.cboField & " like '*" & Me.txtSearchText & "*' "
End If

Then I selected
show only where field Infection contains c
on the form, and this seemed to do the trick. It probably needs some tweaking, but I hope you get the general ID. If this is (more or less) what you need you can remove all the code from the cboField and txtSearchText controls.

BevosAuthor Commented:
This works, jawesome nicobo.

So you are saying i should remove all code ascribed to items and it will still work?

Nico BontenbalCommented:
Yes, delete the
Private Sub cboField_AfterUpdate()
Private Sub txtSearchText_AfterUpdate()
procedures, and it will still work.
BevosAuthor Commented:
Thanks so much Nicobo!
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

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

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