UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Printing Single record from form and subform    
 
   
scarlini
post May 10 2005, 04:41 AM
Post #1

New Member
Posts: 2



I have created a database which has a main form containing "Incident Number" (primary key), which displays details about a certain incident and contains a subform which displays people involved in the incident. There can be many people involved to one incident. What i want to do is get the report to diplay the incident number followed the details of the people involved in that incident. So for example inicdent number 0001 has 3 people involved so it would print all 3 records.

If that isn't possible i would like to the report to print the details of the incident number and the persons details who is being viewed in the subform at the time the button is pressed.

Any help is greatly appreciated
Go to the top of the page
 
+
strive4peace
post May 10 2005, 05:05 AM
Post #2

UtterAccess VIP
Posts: 20,208
From: Colorado



Welcome to UtterAccess

design a report/subreport to show the information (for ALL records)
When you are in the report design, if the report will look similar to the entry form you have, you can copy from form design to report design...

set up a form, called ReportMenu, with:
a combobox to choose incident number
a command button to launch the report

use the combobox to filter the report

once you get this working, you can also put a command button on your entry form to launch the same report and filter for the incident that is displayed, if desired.

here is some general informaiton on Report Filters

It would be best to build a filter string for the report (as opposed to imbedding a parameter in a query)--in this way, you can use comboboxes and listboxes to make it easier for the user to choose criteria and you can ignore criteria when it has not been specified...

here is an example that tests criteria and builds a filter string to use as a parameter in OpenReport

assuming you are in the code behind the ReportMenu form...

CODE
   'tell Access you are going to create a variable to hold text
   dim varFilter as variant
  
   'initialize the variable
   varFilter = Null

   'substitute YOUR controlname in here after "Me."
   'we are testing to see if it is filled out
   'if it is, we are going to make mFilter hold the criteria
   If not IsNull(me.text_controlname ) Then
      varFilter = "[TextFieldname]= '" & me.controlname_for_text  & "'"
   end if
  
   'test the next control
   If not IsNull(me.date_controlname ) Then
       'if we alread have criteria, add AND to specify that and more
      varFilter = (varFilter  & " AND ")  & "[DateFieldname]= #" & me.controlname_for_date  & "#"
   end if

   'test the next control
   If not IsNull(me.numeric_controlname ) Then
      varFilter = (varFilter  & " AND ")  &   "[NumericFieldname]= " & me.controlname_for_number
   end if
  
    if not IsNull(varFilter) then  
       DoCmd.OpenReport "ReportName", acViewPreview, , varFilter
   else
       DoCmd.OpenReport "ReportName", acViewPreview
   end if


I have used
TextFieldname to show how text needs to be delimited - with single quote marks (you can also use double quote marks

DateFieldname to show that dates need to be delimited with #

NumericFieldname to show that numbers are not delimited

each time, we are testing to see if a filter control is filled out.
If it is, we are going to see if we first need to add AND (if the filter string already says something)
Then we are going to add the criteria for that filter

make sure that the referenced fields are in the underlying RecordSource for the report.
Since a filter is applied on the recordset, they do not have to be on the report object (unlike a form)

For a Date Range, you would do:

CODE
   If not IsNull(me.date1_controlname ) Then
      varFilter = (varFilter  & " AND ")  &  "[DateFieldname]>= #" & me.controlname_for_date1  & "#"
   end if

   If not IsNull(me.date2_controlname ) Then
     varFilter = (varFilter  & " AND ")  &  "[DateFieldname] <= #" & me.controlname_for_date2  & "#"
   end if

***

IF you want to also PRINT the criteria on the report

put a LABEL on your PageFooter
name --> Label_Criteria

then, in the OnFormat event of the ReportHeader

CODE
   if len(trim(nz(me.filter,""))) > 0 then
      me.Label_Criteria.Caption = me.filter
      me.Label_Criteria.Visible = true
   else
      me.Label_Criteria.Visible = false
   end if
Go to the top of the page
 
+
scarlini
post May 10 2005, 05:46 AM
Post #3

New Member
Posts: 2



Thanks very much for your help. Will give it a go
Go to the top of the page
 
+
strive4peace
post May 10 2005, 05:49 AM
Post #4

UtterAccess VIP
Posts: 20,208
From: Colorado



you're welcome (IMG:http://www.utteraccess.com/forum/style_emoticons/default/wink.gif)
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 23rd May 2013 - 02:13 PM

Tag cloud: