Print selected record in subform

C

Cyberwolf

I have a form with a subform. THere is no relationship between the 2 as the
main form only contains buttons for running different options and the subform
is the datasource set in datasheet style. I need to print a selected record
from the subform, but have not been able to figure this out. Any suggestiosn?
 
A

Allen Browne

Follow the logic in this article:
Print the record in the form
at:
http://allenbrowne.com/casu-15.html
and change the line:
strWhere = "[ID] = " & Me.[ID]
to:
strWhere = "[ID] = " & Me.[Sub1].Form.[ID]
where Sub1 represents the name of your subform control.

(This assumes the button is on the main form. If it's on the subform, you
have nothing to change.)
 
C

Cyberwolf

Thanks for the reply, my solution is very close to yours. and I think
yhours is a little better as I do not have to filter a single record first.
Here is my solution

Dim stDocName As String

stDocName = "rpt:Current Trial Balance"
DoCmd.OpenReport stDocName, acNormal, , Forms![frm:CUrrent TB]![Current
TB subform].Form.Filter

Yours also checks for dirty records, which I never considered.
--
James Gaylord
Finder of Paths, Hunter of Prey
Ghost of the Night, Shadow of Day
The Wolf


Allen Browne said:
Follow the logic in this article:
Print the record in the form
at:
http://allenbrowne.com/casu-15.html
and change the line:
strWhere = "[ID] = " & Me.[ID]
to:
strWhere = "[ID] = " & Me.[Sub1].Form.[ID]
where Sub1 represents the name of your subform control.

(This assumes the button is on the main form. If it's on the subform, you
have nothing to change.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Cyberwolf said:
I have a form with a subform. THere is no relationship between the 2 as
the
main form only contains buttons for running different options and the
subform
is the datasource set in datasheet style. I need to print a selected
record
from the subform, but have not been able to figure this out. Any
suggestiosn?
--
James Gaylord
Finder of Paths, Hunter of Prey
Ghost of the Night, Shadow of Day
The Wolf
 
Top