Print Report button on Form

  • Thread starter Thread starter administrator
  • Start date Start date
A

administrator

I have a form with a print button. The report has
parameters where it asks for the name of the employee and
date to run the report. Is there anyway to set the print
button to automatically know the parameters for this
report are the current name and current date.
 
Here's what I use; however, it doesn't include current
date field as part of the criteria but you could include
it...

===============
Private Sub cmdPrintCurrentRecord_Click()
On Error GoTo Err_cmdPrintCurrentRecord_Click

Dim stName As String
Dim stDocName As String
Dim stFilter As String

stName = [Field_Name]
stDocName = "rpt_Name_of_Report"
stFilter = "[Field_Name] = " & "'" & stName & "'"

DoCmd.OpenReport stDocName, acNormal, , stFilter

Exit_cmdPrintCurrentRecord_Click:
Exit Sub

Err_cmdPrintCurrentRecord_Click:
MsgBox Err.Description
Resume Exit_cmdPrintCurrentRecord_Click

End Sub
===============

Hopefully helpful,
Jim
 
That worked great for fullname, however, for a second
criteria (bankdate) I can't seem to figure it out. I
don't know enought about programming ... where would you
start the "DIM" part of the procedure or is that even what
you would start with.

Here's what I have so far...

Private Sub Command56_Click()
On Error GoTo Err_Command56_Click

Dim stName As String
Dim stDocName As String
Dim stFilter As String

stName = [FullName]
stDocName = "RPTTickets1"
stFilter = "[FullName] = " & "'" & stName & "'"

DoCmd.OpenReport stDocName, acPreview, , stFilter

Exit_Command56_Click:
Exit Sub

Err_Command56_Click:
MsgBox Err.Description
Resume Exit_Command56_Click

-----Original Message-----
Here's what I use; however, it doesn't include current
date field as part of the criteria but you could include
it...

===============
Private Sub cmdPrintCurrentRecord_Click()
On Error GoTo Err_cmdPrintCurrentRecord_Click

Dim stName As String
Dim stDocName As String
Dim stFilter As String

stName = [Field_Name]
stDocName = "rpt_Name_of_Report"
stFilter = "[Field_Name] = " & "'" & stName & "'"

DoCmd.OpenReport stDocName, acNormal, , stFilter

Exit_cmdPrintCurrentRecord_Click:
Exit Sub

Err_cmdPrintCurrentRecord_Click:
MsgBox Err.Description
Resume Exit_cmdPrintCurrentRecord_Click

End Sub
===============

Hopefully helpful,
Jim
-----Original Message-----
I have a form with a print button. The report has
parameters where it asks for the name of the employee and
date to run the report. Is there anyway to set the print
button to automatically know the parameters for this
report are the current name and current date.
.
.
 
Hi all,

I'm in a similar boat, I have a form with say 25 records,
I have a print button on that form that I want to open the
report that I have created and have it print just that
record that is currently showing on the form...

Any ideas on this...I've been banging my head all day...

Thanks,

Nick


-----Original Message-----
That worked great for fullname, however, for a second
criteria (bankdate) I can't seem to figure it out. I
don't know enought about programming ... where would you
start the "DIM" part of the procedure or is that even what
you would start with.

Here's what I have so far...

Private Sub Command56_Click()
On Error GoTo Err_Command56_Click

Dim stName As String
Dim stDocName As String
Dim stFilter As String

stName = [FullName]
stDocName = "RPTTickets1"
stFilter = "[FullName] = " & "'" & stName & "'"

DoCmd.OpenReport stDocName, acPreview, , stFilter

Exit_Command56_Click:
Exit Sub

Err_Command56_Click:
MsgBox Err.Description
Resume Exit_Command56_Click

-----Original Message-----
Here's what I use; however, it doesn't include current
date field as part of the criteria but you could include
it...

===============
Private Sub cmdPrintCurrentRecord_Click()
On Error GoTo Err_cmdPrintCurrentRecord_Click

Dim stName As String
Dim stDocName As String
Dim stFilter As String

stName = [Field_Name]
stDocName = "rpt_Name_of_Report"
stFilter = "[Field_Name] = " & "'" & stName & "'"

DoCmd.OpenReport stDocName, acNormal, , stFilter

Exit_cmdPrintCurrentRecord_Click:
Exit Sub

Err_cmdPrintCurrentRecord_Click:
MsgBox Err.Description
Resume Exit_cmdPrintCurrentRecord_Click

End Sub
===============

Hopefully helpful,
Jim
-----Original Message-----
I have a form with a print button. The report has
parameters where it asks for the name of the employee and
date to run the report. Is there anyway to set the print
button to automatically know the parameters for this
report are the current name and current date.
.
.
.
 
Nick DeMerchant said:
Hi all,

I'm in a similar boat, I have a form with say 25 records,
I have a print button on that form that I want to open the
report that I have created and have it print just that
record that is currently showing on the form...

Any ideas on this...I've been banging my head all day...

Access OpenReport command has an optional WHERE argument that can apply a filter to
the report as it is run. You need to use that to specify that the Primary Key value
in the report is filtered to agree with the Primary Key value currently showing on
the form.

DoCmd.OpenReport "SomeReport",,,"[PKField] = " & Me![PKField]

(The above assumes PKField is numeric. If text, you would need single quote
delimiters....

DoCmd.OpenReport "SomeReport",,,"[PKField] = '" & Me![PKField] & "'"
 
Back
Top