Creating a report on dynamic data

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a db of hospital patients. The main purpose of the db is to search
those records on a number of different fields. The user is presented with a
form on which they select the search criteria. This builds a string which is
used as the "WHERE:-" clause in opening a second form (DoCmd.OpenForm..) that
displays the results. What I would like to do, and am struggling to
understand, is how to create a report based on the results form, ie have a
button on the results form that would generate and print a report of what is
on the results form. The problem I see is that the data that makes up the
results form is dynamic in that it depends on the user input and is not a
query but a string constructed by the users input "on the fly". The fields to
be displayed are always the same (all the fields of the underlying table)
but the records depend on the search selections and their existance in the db.

Any pointers would be most helpful, TIA

Ian.
 
You might be able to "re-purpose" the where clause used to open the form.
This where clause is available through the Filter property of the form. You
can try code like:

Dim strWhere as String
If Me.FilterOn = True Then
strWhere = Me.Filter
End If
DoCmd.OpenReport "rptYourReport", acPreview, , strWhere
 
Duane,

You're a star, such a simple piece of code but it works a treat, thanks.

If I wanted to print this report do I control the printing from the report
or from the code in the form? I put a button on the report but it is not
accessible in report view mode, sorry if this seems a really basic mistake.
 
I usually place an option group on my form with options to Preview or Print.
The option value for Preview = 2 and Normal/Print = 0. If your option group
name is "grpViewMode" then your code would be:

DoCmd.OpenReport "rptYourReport", Me.grpViewMode, , strWhere
 
Thanks again Duane,

Ian.

Duane Hookom said:
I usually place an option group on my form with options to Preview or Print.
The option value for Preview = 2 and Normal/Print = 0. If your option group
name is "grpViewMode" then your code would be:

DoCmd.OpenReport "rptYourReport", Me.grpViewMode, , strWhere
 
Back
Top