Scott C said:
Thank you for your help. They are from combo boxes displaying column
2. I used a debug.print me.filter and the filter is
((Lookup_myfield.column2 = "Value")). Now when the report opens a
"Enter Parameter Value" dialog box pops asking for
Lookup_myfield.column2
That makes it tough. At one time, I started out to develop a solution
that would build a WHERE clause and incorporate subqueries to deal with
this problem, but I got bogged down and put it aside.
In the absence of such a solution, and faced with the limitations you
have, I can think of three other approaches besides the one you've
already tried.
Approach 1
------------
Have a boolean (yes/no) field in the table which you use solely for the
purpose of flagging the records you want to report. When you click the
button to open your report, you run an update query that clears all
these flags, and then run through the filtered recordset (via the form's
recordset clone) and set the flag field to True for every record in the
recordset. Your report would be based on a query that extracts only the
flagged records.
Disadvantage: you have to update the records just to report them.
Approach 2
------------
Have a work table in which you will store only the primary key of the
records you want to report. When you click the button to open your
report, you run a delete query that empties this table, and then run
through the form's filtered recordset and add the primary key of each
record to the work table. Your report is then based on a query that
inner joins the form's recordsource table to the work table on the
primary key, thus excluding all records that aren't represented in the
work table.
Disadvantage: constantly adding and deleting records from the work table
will encourage database bloat, forcing more frequent compaction. This
may or may not be a problem, depending on the size of the table, and
also could be eliminated by using a temporary, external database for the
work table. I have code for this, if you need it.
Approach 3
------------
Base your report on a query that calls a function for each record to see
if the record is in the form's recordset. In other words, your query
would be something like:
SELECT * FROM MyTable
WHERE fncIsInFormRecordset("YourForm", "ID", [ID])
Here's code for such a function I just threw together, along with a
helper function:
'----- start of code -----
'*** requires reference to the DAO object library ***
Function fncIsInFormRecordset( _
FormName As String, _
FieldName As String, _
FieldValue As Variant) _
As Boolean
With Forms(FormName).RecordsetClone
If .RecordCount = 0 Then Exit Function
.FindFirst "[" & FieldName & "] = " & _
fncSQLLiteral(FieldValue, .Fields(FieldName).Type)
fncIsInFormRecordset = Not .NoMatch
End With
End Function
Function fncSQLLiteral( _
ArgValue As Variant, ValType As Integer) _
As String
Select Case ValType
Case dbDate
If Len(ArgValue & vbNullString) = 0 Then
fncSQLLiteral = "Null"
Else
fncSQLLiteral = Format(ArgValue, "\#mm/dd/yyyy\#")
End If
Case dbText, dbMemo
If IsNull(ArgValue) Then
fncSQLLiteral = "Null"
Else
fncSQLLiteral = _
Chr(34) & _
Replace( _
ArgValue, """", """""", , , vbBinaryCompare _
) & _
Chr(34)
End If
Case Else
If Len(ArgValue & vbNullString) = 0 Then
fncSQLLiteral = "Null"
Else
fncSQLLiteral = ArgValue
End If
End Select
End Function
'----- end of code -----
Disadvantages: This is bound to be relatively slow. Whether that makes
a difference in practice remains to be seen.
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)