JohnLute said:
Hey, Dirk!
The Ubiquitous Guru is ubiquitous as ever! Hope your knee(s) are
cooperating.
Here are the recourd sources:
Report record source:
SELECT tblProfiles.*
FROM tblProfiles INNER JOIN tblProfilesRevisions ON
tblProfiles.txtProfileID = tblProfilesRevisions.txtProfileID;
Subreport record source:
tblProfilesRevisions
As it turns out I do have a unique field to identify each revision:
tblProfilesRevisions.numProfilesRevisionsID
This is an autonumber field.
I'm not sure what you mean by the "WhereCondition argument of the
call to OpenForm." Do you mean in the button's event procedure?
Yes, that's what I mean, except that I should have said "OpenReport",
not "OpenForm". Sorry about that slip of the brain. With the
information you've provided, I can revise your event procedure as
follows:
'----- start of revised code -----
Private Sub cmdPreviewRevision_Click()
On Error GoTo Err_cmdPreviewRevision_Click
' Save current record, if it hasn't been saved yet.
If Me.Dirty Then Me.Dirty = False
' Open report in preview mode, filtered for the current revision.
DoCmd.OpenReport "rptPKRevisions", acPreview, , _
"[numProfilesRevisionsID] = " & Me!numProfilesRevisionsID
Exit_cmdPreviewRevision_Click:
Exit Sub
Err_cmdPreviewRevision_Click:
MsgBox Err.Description
Resume Exit_cmdPreviewRevision_Click
End Sub
'----- end of revised code -----
There are a couple of possible complications that may exist and affect
whether or not the above code will work. First, the above code assumes
that cmdPreviewRevision is on a form that either has a control named
"numProfilesRevisionsID", or has such a field in the recordset to which
it's bound. If that's not the case -- for example, if the field has
some other name, or if numProfilesRevisionsID is on a subform and the
button is on a main form, or vice versa -- the code will fail.
Second, you refer to a subreport based on tblProfilesRevisions, but the
main report is based on a query that joins tblProfiles to that same
table. That's an odd thing to do -- normally you'd either base the main
report on such a query and not use a subreport, or you'd keep the
subreport but base the main report on tblProfiles alone. Maybe I'm not
imagining correctly the way you have set this up. However, if the main
report is *not* based on a query that includes tblProfilesRevisions,
then filtering it by numProfilesRevisionsID is not going to work.
There's no direct way to filter the subform, without more code than
ought to be necessary. So I *think* you ought to be using just a main
report, with no subreport, but grouped by txtProfileID. This is all
speculation on my part, though.