How do Iprint the current form record in report format with one bu

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

Guest

How do I print the current form record in report form with the touch of one
button? I have it currently set to request a parameter, but that is not the
way my boss wants it to be done. I can't seem to find a macro that will work
for me because I cannot find another way to specify the current record. Any
help would be appreciated.
 
This is asked and answered very often. Please do a search before you post a
new thread...

Private Sub cmdPrint_Click()

Dim strWhere As String

If Me.Dirty Then 'Save any edits.

Me.Dirty = False

End If

If Me.NewRecord Then 'Check there is a record to print

MsgBox "Select a record to print"

Else

strWhere = "[ID] = " & Me.[ID]

DoCmd.OpenReport "MyReport", acViewPreview, , strWhere

End If

End Sub



Notes: If your primary key is a Text type field (not a Number type field),
you need extra quotes: strWhere = "[ID] = """ & Me.[ID] & """"

If you want the report to print without preview, replace acViewPreview with
acViewNormal.



See also: http://allenbrowne.com/casu-15.html
 
This is bringing up a report, but it isn't simply the current record only.
It is pulling up all the records from the form.

Rick B said:
This is asked and answered very often. Please do a search before you post a
new thread...

Private Sub cmdPrint_Click()

Dim strWhere As String

If Me.Dirty Then 'Save any edits.

Me.Dirty = False

End If

If Me.NewRecord Then 'Check there is a record to print

MsgBox "Select a record to print"

Else

strWhere = "[ID] = " & Me.[ID]

DoCmd.OpenReport "MyReport", acViewPreview, , strWhere

End If

End Sub



Notes: If your primary key is a Text type field (not a Number type field),
you need extra quotes: strWhere = "[ID] = """ & Me.[ID] & """"

If you want the report to print without preview, replace acViewPreview with
acViewNormal.



See also: http://allenbrowne.com/casu-15.html




--
Rick B



Tboartz said:
How do I print the current form record in report form with the touch of
one
button? I have it currently set to request a parameter, but that is not
the
way my boss wants it to be done. I can't seem to find a macro that will
work
for me because I cannot find another way to specify the current record.
Any
help would be appreciated.
 
I have used the same code that is posted and it has worked fine for me. It
only prints the current record. I have included the modified code below.
Which is the same one just with my fields.

Maybe some thing is a liitle off with yours.



Private Sub cmdPrint_Sites_Click()
Dim strWhere As String

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[Building Number] = """ & Me.[Building Number] & """"
DoCmd.OpenReport "For_printing_site_info", acViewPreview, , strWhere
End If
End Sub

--
Your help is appreciated
Thank You


Tboartz said:
This is bringing up a report, but it isn't simply the current record only.
It is pulling up all the records from the form.

Rick B said:
This is asked and answered very often. Please do a search before you post a
new thread...

Private Sub cmdPrint_Click()

Dim strWhere As String

If Me.Dirty Then 'Save any edits.

Me.Dirty = False

End If

If Me.NewRecord Then 'Check there is a record to print

MsgBox "Select a record to print"

Else

strWhere = "[ID] = " & Me.[ID]

DoCmd.OpenReport "MyReport", acViewPreview, , strWhere

End If

End Sub



Notes: If your primary key is a Text type field (not a Number type field),
you need extra quotes: strWhere = "[ID] = """ & Me.[ID] & """"

If you want the report to print without preview, replace acViewPreview with
acViewNormal.



See also: http://allenbrowne.com/casu-15.html




--
Rick B



Tboartz said:
How do I print the current form record in report form with the touch of
one
button? I have it currently set to request a parameter, but that is not
the
way my boss wants it to be done. I can't seem to find a macro that will
work
for me because I cannot find another way to specify the current record.
Any
help would be appreciated.
 
Well, I got it to work on one of the forms. Even though all info was applied
to the other three verbatim, I could not get it to work properly for them. I
see that you have added a few extra quotation marks to the WhereCondition
statement. Let me try that and see.

Okay, I got this to work on another of the forms now. Let me ask you this
if you don't mind. If you duplicate the same code on multiple forms on the
same mdb, do you need to alter the code in any way to differentiate between
the forms other than altering the record source (I mean the table)? Also,
can you tell me what the quotation marks represent in code?

Thank you for your help =). Unfortunately I have had no training in VBA or
programming code so this is me eeking by with some assistance and very minor
self-teaching. So you can see where I am in this heh.

Phill said:
I have used the same code that is posted and it has worked fine for me. It
only prints the current record. I have included the modified code below.
Which is the same one just with my fields.

Maybe some thing is a liitle off with yours.



Private Sub cmdPrint_Sites_Click()
Dim strWhere As String

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[Building Number] = """ & Me.[Building Number] & """"
DoCmd.OpenReport "For_printing_site_info", acViewPreview, , strWhere
End If
End Sub

--
Your help is appreciated
Thank You


Tboartz said:
This is bringing up a report, but it isn't simply the current record only.
It is pulling up all the records from the form.

Rick B said:
This is asked and answered very often. Please do a search before you post a
new thread...

Private Sub cmdPrint_Click()

Dim strWhere As String

If Me.Dirty Then 'Save any edits.

Me.Dirty = False

End If

If Me.NewRecord Then 'Check there is a record to print

MsgBox "Select a record to print"

Else

strWhere = "[ID] = " & Me.[ID]

DoCmd.OpenReport "MyReport", acViewPreview, , strWhere

End If

End Sub



Notes: If your primary key is a Text type field (not a Number type field),
you need extra quotes: strWhere = "[ID] = """ & Me.[ID] & """"

If you want the report to print without preview, replace acViewPreview with
acViewNormal.



See also: http://allenbrowne.com/casu-15.html




--
Rick B



How do I print the current form record in report form with the touch of
one
button? I have it currently set to request a parameter, but that is not
the
way my boss wants it to be done. I can't seem to find a macro that will
work
for me because I cannot find another way to specify the current record.
Any
help would be appreciated.
 
The extra quotes is because my primary key is a text and not a number. See
below.

** Note: If your primary key is a Text type field (not a Number type field),
you need extra quotes: strWhere = "[ID] = """ & Me.[ID] & """"

As for altering the code, other than the source. The answer is no; it should
work just as well .

P.S. Don't feel bad I'm a newbie also.

Your help is appreciated
Thank You


Tboartz said:
Well, I got it to work on one of the forms. Even though all info was applied
to the other three verbatim, I could not get it to work properly for them. I
see that you have added a few extra quotation marks to the WhereCondition
statement. Let me try that and see.

Okay, I got this to work on another of the forms now. Let me ask you this
if you don't mind. If you duplicate the same code on multiple forms on the
same mdb, do you need to alter the code in any way to differentiate between
the forms other than altering the record source (I mean the table)? Also,
can you tell me what the quotation marks represent in code?

Thank you for your help =). Unfortunately I have had no training in VBA or
programming code so this is me eeking by with some assistance and very minor
self-teaching. So you can see where I am in this heh.

Phill said:
I have used the same code that is posted and it has worked fine for me. It
only prints the current record. I have included the modified code below.
Which is the same one just with my fields.

Maybe some thing is a liitle off with yours.



Private Sub cmdPrint_Sites_Click()
Dim strWhere As String

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[Building Number] = """ & Me.[Building Number] & """"
DoCmd.OpenReport "For_printing_site_info", acViewPreview, , strWhere
End If
End Sub

--
Your help is appreciated
Thank You


Tboartz said:
This is bringing up a report, but it isn't simply the current record only.
It is pulling up all the records from the form.

:

This is asked and answered very often. Please do a search before you post a
new thread...

Private Sub cmdPrint_Click()

Dim strWhere As String

If Me.Dirty Then 'Save any edits.

Me.Dirty = False

End If

If Me.NewRecord Then 'Check there is a record to print

MsgBox "Select a record to print"

Else

strWhere = "[ID] = " & Me.[ID]

DoCmd.OpenReport "MyReport", acViewPreview, , strWhere

End If

End Sub



Notes: If your primary key is a Text type field (not a Number type field),
you need extra quotes: strWhere = "[ID] = """ & Me.[ID] & """"

If you want the report to print without preview, replace acViewPreview with
acViewNormal.



See also: http://allenbrowne.com/casu-15.html




--
Rick B



How do I print the current form record in report form with the touch of
one
button? I have it currently set to request a parameter, but that is not
the
way my boss wants it to be done. I can't seem to find a macro that will
work
for me because I cannot find another way to specify the current record.
Any
help would be appreciated.
 
Back
Top