Link to home
Start Free TrialLog in
Avatar of andybrooke
andybrooke

asked on

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

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

Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image



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?


to a[pply the criteria

    stDocName = "rptDMPLOA"

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

    DoCmd.PrintOut acPages, , , , cint(Me.Combo1156)
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial