• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • Last Modified:

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

0
andybrooke
Asked:
andybrooke
  • 3
1 Solution
 
Rey Obrero (Capricorn1)Commented:


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
 
Rey Obrero (Capricorn1)Commented:
to a[pply the criteria

    stDocName = "rptDMPLOA"

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

    DoCmd.PrintOut acPages, , , , cint(Me.Combo1156)
0
 
Rey Obrero (Capricorn1)Commented:
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now