R
rupertsland
I am building a search/filter form to make it easier for users to filter data
from an underlying table. The form has a subform, 4 textbox controls (project
name, filing number, report series, and publication year) into which users
can enter criteria, and a 'Search' command button. I figured out how to use
the BuildCriteria method to filter a single field. However, figuring out the
VB code needed to concatenate all 4 criteria strings has been a major
stumbling block.
Microsoft Access 2003's online VisualBasic offers this suggestion:
"...if you wish to construct a criteria string that refers to multiple
fields, you must create the strings and concatenate them yourself. For
example, if you wish to construct criteria for a filter to show records for
orders placed after 1-1-95 and for which freight is less than $50, you would
need to use the BuildCriteria method twice and concatenate the resulting
strings."
How should I properly concatenate the resulting strings?
Also, if a user leaves one or more textbox controls empty, can this create
any problems when you concatenate the strings and apply the filter? If so,
what should I do to ensure the filter takes this into account?
Here's the VB code I wrote, which uses the BuildCriteria method:
strFilterProj = BuildCriteria("PROJ_NAME", dbText, strInputProj)
strFilterFile = BuildCriteria("RPT_FILENUM", dbDouble, strInputFile)
strFilterSeries = BuildCriteria("RPT_SERIES", dbText, strInputSeries)
strFilterPubYear = BuildCriteria("RPT_YEAR", dbDouble, strInputPubYear)
' Concatenate criteria strings
strFilter = (here is where the criteria strings would get concatenated)
' Set Filter property to apply filter
frm.Filter = strFilter
' Set FilterOn property; form now shows filtered records.
frm.FilterOn = True
from an underlying table. The form has a subform, 4 textbox controls (project
name, filing number, report series, and publication year) into which users
can enter criteria, and a 'Search' command button. I figured out how to use
the BuildCriteria method to filter a single field. However, figuring out the
VB code needed to concatenate all 4 criteria strings has been a major
stumbling block.
Microsoft Access 2003's online VisualBasic offers this suggestion:
"...if you wish to construct a criteria string that refers to multiple
fields, you must create the strings and concatenate them yourself. For
example, if you wish to construct criteria for a filter to show records for
orders placed after 1-1-95 and for which freight is less than $50, you would
need to use the BuildCriteria method twice and concatenate the resulting
strings."
How should I properly concatenate the resulting strings?
Also, if a user leaves one or more textbox controls empty, can this create
any problems when you concatenate the strings and apply the filter? If so,
what should I do to ensure the filter takes this into account?
Here's the VB code I wrote, which uses the BuildCriteria method:
strFilterProj = BuildCriteria("PROJ_NAME", dbText, strInputProj)
strFilterFile = BuildCriteria("RPT_FILENUM", dbDouble, strInputFile)
strFilterSeries = BuildCriteria("RPT_SERIES", dbText, strInputSeries)
strFilterPubYear = BuildCriteria("RPT_YEAR", dbDouble, strInputPubYear)
' Concatenate criteria strings
strFilter = (here is where the criteria strings would get concatenated)
' Set Filter property to apply filter
frm.Filter = strFilter
' Set FilterOn property; form now shows filtered records.
frm.FilterOn = True