Assuming that you are opening the report from a button on the form, all you
need do is include a Where parameter in the command to open the report, such
as :
DoCmd.OpenReport "rptMyReportName", acPreview, , cboxFieldName & " = " &
txtValue
This will work fine if your fields are numeric. If they are text you'll
need:
DoCmd.OpenReport "rptMyReportName", acPreview, , cboxFieldName & " = '"
& txtValue & "'"
and if they are datetime values you'll need:
DoCmd.OpenReport "rptMyReportName", acPreview, , cboxFieldName & " = #"
& txtValue & "#"
If the fields are mixed datatypes, the easiest way is probably to include a
field for the datatype in the combobox recordsource (it does not have to be
visible), and use it to build the Where clause, such as:
Dim strWhere as String
Select Case cboxFieldName.Column(1) 'assuming you add a datatype
field as the second field of your combobox source
Case "text"
strWhere = cboxFieldName & " = " & txtValue
Case "numeric"
strWhere = cboxFieldName & " = '" & txtValue & "'"
Case "datetime"
strWhere = cboxFieldName & " = #" & txtValue & "#"
Case Else
End Select
DoCmd.OpenReport "rptMyReportName", acPreview, , strWhere
You could use a number to indicate the datatype (eg. 1 = numeric, 2 = text,
etc), and use Case 1, Case 2, etc.
You may also need to manipulate date values to get the correct format for
the query, if the textbox control is formatting them.
HTH,
Rob