Solved

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

Posted on 2011-09-08
3
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…

690 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