help print current recort on report

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

Guest

Hi
I have a subform on a form. On the main form I have a button that I want to
use to print a report with the fileds of the whole form including the ones in
the subform.
Please help
Thanks
George
 
This is an example of the Event Procedure you could use in the Click event
of your command button. It assumes you have a numeric field named "MyID"
that uniquely identifies the record in the form:

Private Sub cmdPrint_Click()
Dim strWhere As String
If Me.Dirty Then 'save first
Me.Dirty = False
End If
If Me.NewRecord Then
MsgBox "Select the record to print."
Else
strWhere = "[MyID] = " & Me.[MyID]
DoCmd.OpenReport "MyReport", acViewPreview, , strWhere
End If
End Sub
 
So you need to refer to the subform in order to get the value to uniquely
identify your record?

If so, and you do not know how to refer to the value in the subform, see:
Referring to Controls on a Subform
at:
http://members.iinet.net.au/~allenbrowne/casu-04.html

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

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

George said:
Thanks for the quick reply.
I was trying this but it does not work as it can't find the field on the
form. The field is located on a subform that gets is data from a select
query
and is linked with its parent form that gets its data from a table.
Thanks george

Allen Browne said:
This is an example of the Event Procedure you could use in the Click
event
of your command button. It assumes you have a numeric field named "MyID"
that uniquely identifies the record in the form:

Private Sub cmdPrint_Click()
Dim strWhere As String
If Me.Dirty Then 'save first
Me.Dirty = False
End If
If Me.NewRecord Then
MsgBox "Select the record to print."
Else
strWhere = "[MyID] = " & Me.[MyID]
DoCmd.OpenReport "MyReport", acViewPreview, , strWhere
End If
End Sub


GeorgeC said:
Hi
I have a subform on a form. On the main form I have a button that I
want
to
use to print a report with the fileds of the whole form including the
ones
in
the subform.
Please help
Thanks
George
 
Thanks allot it works now.

Allen Browne said:
So you need to refer to the subform in order to get the value to uniquely
identify your record?

If so, and you do not know how to refer to the value in the subform, see:
Referring to Controls on a Subform
at:
http://members.iinet.net.au/~allenbrowne/casu-04.html

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

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

George said:
Thanks for the quick reply.
I was trying this but it does not work as it can't find the field on the
form. The field is located on a subform that gets is data from a select
query
and is linked with its parent form that gets its data from a table.
Thanks george

Allen Browne said:
This is an example of the Event Procedure you could use in the Click
event
of your command button. It assumes you have a numeric field named "MyID"
that uniquely identifies the record in the form:

Private Sub cmdPrint_Click()
Dim strWhere As String
If Me.Dirty Then 'save first
Me.Dirty = False
End If
If Me.NewRecord Then
MsgBox "Select the record to print."
Else
strWhere = "[MyID] = " & Me.[MyID]
DoCmd.OpenReport "MyReport", acViewPreview, , strWhere
End If
End Sub


Hi
I have a subform on a form. On the main form I have a button that I
want
to
use to print a report with the fileds of the whole form including the
ones
in
the subform.
Please help
Thanks
George
 
Back
Top