Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print a report from within Report VBA 1

Status
Not open for further replies.

tqeonline

MIS
Oct 5, 2009
304
US
Is it possible to do some code within the Detail_Format then have it print once that code is processed?

Explanation:
I have a half page report. I duplicated it so I could have 2 on one page. I then made a box to cover the second have if I didn't have to print 2 reports.

Each report has the same fields. The only difference is there is a "Serial" box that increases upto the total number of Parts. If she has 5 parts, then there will be 5 half page documents, Starting with Page 1 Serial 1 ending with Page 5 Serial 5.

I have written the code so it processes one page and then *should* print that one page, then it will make the 2nd page... etc until the Serial = QTY at which point it closes.

Here is the code:

Code:
If Qty <> Serial Then
    For x = 1 To Qty
        Cover.Visible = True
        txtSupplier.Caption = "Total Quality Instrumentation"
        txtPartName.Caption = Part_Name
        txtPartNo.Caption = PartNumber
        txtDLS.Caption = DLS
        txtPLS.Caption = PLS
        txtDrawing.Caption = SubmissionDate
        txtST.Caption = "R"
        txtRev.Caption = Rev
        txtPONumber.Caption = Purchase
        txtProject.Caption = Program
        txtSerial.Caption = Serial
        Serial = Serial + 1
        If Serial = Qty Then
            x = Qty
        ElseIf Serial <> Qty Then
            Cover.Visible = False
            txtSupplier2.Caption = "Total Quality Instrumentation"
            txtPartName2.Caption = Part_Name
            txtPartNo2.Caption = PartNumber
            txtDLS2.Caption = DLS
            txtPLS2.Caption = PLS
            txtDrawing2.Caption = SubmissionDate
            txtSt2.Caption = "R"
            txtRev2.Caption = Rev
            txtPoNumber2.Caption = Purchase
            txtProject2.Caption = Program
            txtSerial2.Caption = Serial
            Serial = Serial + 1
            If Serial = Qty Then
                x = Qty
            End If
        End If
        DoCmd.PrintOut
    Next x
End If

DoCmd.PrintOut just prints the main form not the Report.

Could i open the report in ACNormal and then just have it pause after each page is developed?
 
I was able to figure out a way to make it work.

I created a form that controls the printing:

Here is the code:
Code:
If Qty <> Serial Then
    For x = 1 To Qty
        If Serial < Qty Then
            If x = 1 Then
                Serial = Serial
                Serial2 = Serial + 1
            ElseIf x > 1 Then
                If x + 1 = Qty Then
                    Serial = Serial + 1
                    Serial2 = 0
                Else
                    Serial = Serial + 1
                    Serial2 = Serial + 1
                End If
            End If
            
            If Serial < 10 Then
                Serial = Right(Serial, 1)
                Serial = "000" & Serial
            ElseIf Serial > 9 Then
                Serial = Right(Serial, 2)
                Serial = "00" & Serial
            End If
            
            If Serial2 <> 0 And Serial2 < 10 Then
                Serial2 = Right(Serial2, 1)
                Serial2 = "000" & Serial2
            ElseIf Serial2 > 9 Then
                Serial2 = Right(Serial, 2)
                Serial2 = "00" & Serial2
            End If
            stDocName = "rptPartTag"
            DoCmd.OpenReport stDocName, acNormal
            Serial = Serial + 1
            DoEvents
        End If
    Next x
End If

And here is the code in the Detail section of the report

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Serial2 = 0 Then
    Cover.Visible = True
Else
    Cover.Visible = False
End If

txtSupplier.Caption = "Total Quality Instrumentation"
txtPartName.Caption = Part_Name
txtPartNo.Caption = PartNumber
txtDLS.Caption = DLS
txtPLS.Caption = PLS
txtDrawing.Caption = SubmissionDate
txtST.Caption = "R"
txtRev.Caption = Rev
txtPONumber.Caption = Purchase
txtProject.Caption = Program
txtSerial.Caption = Serial

txtSupplier2.Caption = "Total Quality Instrumentation"
txtPartName2.Caption = Part_Name
txtPartNo2.Caption = PartNumber
txtDLS2.Caption = DLS
txtPLS2.Caption = PLS
txtDrawing2.Caption = SubmissionDate
txtSt2.Caption = "R"
txtRev2.Caption = Rev
txtPoNumber2.Caption = Purchase
txtProject2.Caption = Program
txtSerial2.Caption = Serial2
End Sub

I know that it could probably be more efficient or done other ways. But it works flawless as of right now.

Thanks guys!
 
I'm not sure what your basic specification/need is but I expect you are working way too hard to accomplish it. Does this question relate to thread703-1584114? If so, you should have replied there. Did you even check the link I posted?

Duane
Hook'D on Access
MS Access MVP
 
It doesn't relate to that forum. One would of required a Database and one doesn't.

Your link did help but it wouldn't of helped me get 2 half page reports onto one page. It was just taking the code and putting it into a database then running a query off of that database.

I figured it was 6 to 1, 1/2 dozen to the other. It would of taken me just as long if not longer to create a suffice database and have the script to write to it.

But I do appreciate your link. I saved it for future reference.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top