Solved

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

Posted on 2011-09-08
3
261 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 119

Expert Comment

by:Rey Obrero
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 119

Expert Comment

by:Rey Obrero
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 119

Accepted Solution

by:
Rey Obrero 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

760 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

20 Experts available now in Live!

Get 1:1 Help Now