Solved

Clean up very dirty code and simplify its task to print a specified number of pages

Posted on 2011-09-08
3
263 Views
Last Modified: 2012-05-12
Hi EE.
I have created VBA that works but is very dirty code. And is infinate. Can anyone help me rewrite this to be clean. as my code is so long i have only pasted the first few lines but you will see and guess what the rest would say:

The code is to simply print a report but print as many pages as what number appears in a specific field.
I.E. if the field says number "3"  then it prints 3 pages. If it says "5" then it prints 5.  and so on.  as a number from 1 - 99 can be selected you can imagine how long the code is.
If Me.Combo1156 = "1" Then

    stDocName = "rptDMPLOA"

    stLinkCriteria = "[PPIClientID]=" & Me![PPIClientID]
    DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria
End If


If Me.Combo1156 = "2" Then

    stDocName = "rptDMPLOA"

    stLinkCriteria = "[PPIClientID]=" & Me![PPIClientID]
    DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria

    stDocName = "rptDMPLOA"

    stLinkCriteria = "[PPIClientID]=" & Me![PPIClientID]
    DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria
End If
    
If Me.Combo1156 = "3" Then

    stDocName = "rptDMPLOA"

    stLinkCriteria = "[PPIClientID]=" & Me![PPIClientID]
    DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria

    stDocName = "rptDMPLOA"

    stLinkCriteria = "[PPIClientID]=" & Me![PPIClientID]
    DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria
    
    stDocName = "rptDMPLOA"

    stLinkCriteria = "[PPIClientID]=" & Me![PPIClientID]
    DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria
End If
    
If Me.Combo1156 = "4" Then

    stDocName = "rptDMPLOA"

    stLinkCriteria = "[PPIClientID]=" & Me![PPIClientID]
    DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria

    stDocName = "rptDMPLOA"

    stLinkCriteria = "[PPIClientID]=" & Me![PPIClientID]
    DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria
    
    stDocName = "rptDMPLOA"

    stLinkCriteria = "[PPIClientID]=" & Me![PPIClientID]
    DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria
    
    stDocName = "rptDMPLOA"

    stLinkCriteria = "[PPIClientID]=" & Me![PPIClientID]
    DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria
End If

Open in new window

0
Comment
Question by:andybrooke
  • 3
3 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 36502171


you can use this codes to print multiple copies of report

stDocName = "rptDMPLOA"


DoCmd.SelectObject acReport, stDocName, True
'
DoCmd.PrintOut , , , , cint(Me.Combo1156)



where are you calling the codes?


0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 36502180
to a[pply the criteria

    stDocName = "rptDMPLOA"

    stLinkCriteria = "[PPIClientID]=" & Me![PPIClientID]
    DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria

    DoCmd.PrintOut acPages, , , , cint(Me.Combo1156)
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 36502203
correction

to a[pply the criteria

    stDocName = "rptDMPLOA"

    stLinkCriteria = "[PPIClientID]=" & Me![PPIClientID]
    DoCmd.OpenReport stDocName, acviewpreview, , stLinkCriteria

    DoCmd.PrintOut acPages, , , , cint(Me.Combo1156)
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now