To open a report by users input of report # and have it print.

G

Guest

Hi
I have a button on main switch board for "Print by Report #" it opens input message to type the report number they are looking for. I have a table "tblBPLReport" that has "ReportID" as auto# and "BPLReport" as a text(for the report number, Can have numbers and Alphabetical.) both are set to Primary keys.
I have my report as "rptMasterBPLReport" and its "record source" is off "qryBPLReport
The Report form "frmMainForm" its Record Source is off "tblBPLReport" and the Report "text box's" Control Source is off "BPLReport

I tried this code from the button "Print by Report #" as an OnClick Event and it just goes and open the report from the first one in line regardless to the report number user is inputting.
-------------------------------------
Option Compare Databas
Option Explici
---------------------------------------
Private Sub PrintByReport__Click(
On Error GoTo Err_PrintByReport__Clic

Dim stDocName As Strin
Dim intUserRespond As Intege
Dim intReportNumber As Intege
Dim strWhere As Strin

If Me.Dirty Then 'save any edit
Me.Dirty = Fals
Els
intReportNumber = InputBox("Please enter the report number you wish to print"
stDocName = "rptMasterBPLReport
DoCmd.OpenReport stDocName, acViewPreview, , strWher
strWhere = "[qryBPLReport] = """"& Me.[qryBPLReport]""""
End I

Exit_PrintByReport__Click
Exit Su

Err_PrintByReport__Click
MsgBox Err.Descriptio
Resume Exit_PrintByReport__Clic

End Su

I need it to open the right report and be able to print it without printing ALL of the reports. PLEASE HELP

Thank you

Nadi
 
M

Marshall Barton

Nadir said:
I have a button on main switch board for "Print by Report #" it opens input message to type the report number they are looking for. I have a table "tblBPLReport" that has "ReportID" as auto# and "BPLReport" as a text(for the report number, Can have numbers and Alphabetical.) both are set to Primary keys.
I have my report as "rptMasterBPLReport" and its "record source" is off "qryBPLReport"
The Report form "frmMainForm" its Record Source is off "tblBPLReport" and the Report "text box's" Control Source is off "BPLReport"

I tried this code from the button "Print by Report #" as an OnClick Event and it just goes and open the report from the first one in line regardless to the report number user is inputting.
--------------------------------------
Option Compare Database
Option Explicit
----------------------------------------
Private Sub PrintByReport__Click()
On Error GoTo Err_PrintByReport__Click

Dim stDocName As String
Dim intUserRespond As Integer
Dim intReportNumber As Integer
Dim strWhere As String

If Me.Dirty Then 'save any edits
Me.Dirty = False
Else
intReportNumber = InputBox("Please enter the report number you wish to print")
stDocName = "rptMasterBPLReport"
DoCmd.OpenReport stDocName, acViewPreview, , strWhere
strWhere = "[qryBPLReport] = """"& Me.[qryBPLReport]"""""
End If

Exit_PrintByReport__Click:
Exit Sub

Err_PrintByReport__Click:
MsgBox Err.Description
Resume Exit_PrintByReport__Click

End Sub

I need it to open the right report and be able to print it without printing ALL of the reports.


You never use the value of intReportNumber anywhere??

Also, strWhere must be assigned before you open the report
and the quotes are out of whack.

I think(?) your different reports are just one report
filtered to just the records with the ReportNumber, if so
then maybe this is all you need:

intReportNumber = InputBox("Please enter. . .
strWhere = "[qryBPLReport] = """ & intReportNumber & """"
stDocName = "rptMasterBPLReport"
DoCmd.OpenReport stDocName, acViewPreview, , strWhere

Pay close attention to the number of quotes in each place.

If that's not what you're looking for, could you explain
more about what you mean by these different reports and how
you decide which one is which?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top