UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Print Report With User Input # Copies, Access 2013    
 
   
esturgesjr
post May 23 2019, 12:59 PM
Post#1



Posts: 69
Joined: 12-March 04



Hello, UA Gurus!

I have what I thought was a simple request, but much searching here and other internet sites has got me nowhere. Of course, I usual, I may not be seeing the forest for the trees.

Anyway, I have a report that I want to control how many copies are printed at runtime. It is one report in a series of reports that are chosen via check boxes. What I'd like to do is be able to have this one report (when chosen) to pause until user chooses print count from an InputBox. Tried to use the InputBox in the Copies section of PrintOut method with no luck. Nothing happens. I then tried the following bit of code that I found in UA with also no success. Any ideas to set me straight? Or am I barking up a useless tree?

CODE
Dim i As Integer
    strInput = InputBox(Prompt:="Provide number of copies", Title:="# of Copies")
    If strInput = "" Then
    MsgBox ("cancel was pressed")
        ElseIf Not IsNumeric(strInput) Then
        MsgBox ("not a valid number input")
            Else
            i = CInt(strInput)
            DoCmd.PrintOut , , , , i
            DoCmd.Close
    End If


Many thanks in advance!

--------------------
Eddie
Go to the top of the page
 
June7
post May 23 2019, 01:35 PM
Post#2



Posts: 613
Joined: 25-January 16



What does 'no success' mean - error message, wrong result, nothing happens?

Code does not show opening report first. Assuming it is open already, your code should work.

Have you step debugged?


--------------------
Attach File Manager is below Advanced editor window, click Go Advanced below Quick Reply window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
DEBUG! DEBUG! DEBUG! http://www.cpearson.com/Excel/DebuggingVBA.aspx
Go to the top of the page
 
ADezii
post May 23 2019, 01:36 PM
Post#3



Posts: 2,395
Joined: 4-February 07
From: USA, Florida, Delray Beach


Try opening the Report in Print Preview Mode prior to invoking the PrintOut() Method:
CODE
Const conREPORT_NAME = "Supplier Address Book"
Const conCOPIES = 4

With DoCmd
  .OpenReport conREPORT_NAME, acViewPreview
  .PrintOut , , , , conCOPIES
End With

Go to the top of the page
 
esturgesjr
post May 23 2019, 03:36 PM
Post#4



Posts: 69
Joined: 12-March 04



June7: Nothing happens.

The database tracks calls from my volunteer fire company. After data from most recent calls is logged, then certain reports are run.

Here's the code behind the "Print" button on the form that runs through a loop to see which reports have been "ticked" to print and prints them in the selected order:

CODE
Private Sub btnPrint_Click()
    If Me.chkAll = True Then
        For intLoop = 18 To 26
        DoCmd.OpenReport DLookup("RptName", "tblReports", "RptNumber = " & intLoop), acViewNormal
        Next intLoop
    Else
        For intLoop = 18 To 26
        If Me.Controls("chk" & intLoop) = True Then
            DoCmd.OpenReport DLookup("RptName", "tblReports", "RptNumber = " & intLoop), acViewNormal
        End If
        Next intLoop
    End If
        For i = 18 To 26
        Me.Controls("chk" & i) = False
        Next i
        Me.chkAll = False
    Me.Refresh
End Sub


Most reports only require one copy, but one report could be anything from 1 copy to 50. I'd like to be able to pause that report prior to printing to accept input as to # of copies, then let the routine continue to the end. The snippet of code I posted previously is in the On Open property of the specific report.

I didn't debug, but assume the code stops at my snippet as the form doesn't refresh with all checkboxes empty.

ADezii: As stated above, the report should be open at the time the snippet of code is supposed to run, but not in Print Preview mode. I'll see if that makes a difference.

--------------------
Eddie
Go to the top of the page
 
tina t
post May 23 2019, 04:27 PM
Post#5



Posts: 5,963
Joined: 11-November 10
From: SoCal, USA


rather than trying to get x copies via code in the report's module, i'd handle it in the procedure behind the Print button on the form, as

CODE
Private Sub btnPrint_Click()

    Dim strRptName As String, strCopies As String, i As Integer

    If Me.chkAll = True Then
        For intLoop = 18 To 26
        DoCmd.OpenReport DLookup("RptName", "tblReports", "RptNumber = " & intLoop), acViewNormal
        Next intLoop
    Else
        For intLoop = 18 To 26
        If Me.Controls("chk" & intLoop) = True Then
            strRptName = DLookup("RptName", "tblReports", "RptNumber = " & intLoop)
            If str = "MySpecialReportName" Then
                DoCmd.OpenReport strRptName, acPreview
                i = GetPrintCopies
                DoCmd.PrintOut , , , , i
                DoCmd.Close acReport, strRptName, acSaveNo
            Else
                DoCmd.OpenReport strRptName, acViewNormal
            End If
        End If
        Next intLoop
    End If
    For i = 18 To 26
        Me.Controls("chk" & i) = False
    Next i
    Me.chkAll = False
    Me.Refresh
End Sub

Private Function GetPrintCopies() As Integer

    Dim i As Integer, strInput As String

    strInput = InputBox(Prompt:="Provide number of copies", Title:="# of Copies")
    If strInput = "" Then
        MsgBox ("cancel was pressed")
        i = 1
    ElseIf Not IsNumeric(strInput) Then
        MsgBox ("not a valid number input")
        i = 1
    Else
        i = CInt(strInput)
    End If

    GetPrintCopies = i

End Function

hth
tina

--------------------
"the wheel never stops turning"
Go to the top of the page
 
esturgesjr
post May 23 2019, 05:08 PM
Post#6



Posts: 69
Joined: 12-March 04



tina t: and yet again, you saved my butt! Works perfectly! I had thought about putting the count code in there, but wasn't sure where to nestle it; you made my day (and evening)! Just returned from a fire call and there you were! Many, many thanks! This Bud's for you! cheers.gif

Thanks also to June7 and ADezii for jumping in as well. Much appreciated!
This post has been edited by esturgesjr: May 23 2019, 05:12 PM

--------------------
Eddie
Go to the top of the page
 
tina t
post May 24 2019, 03:57 PM
Post#7



Posts: 5,963
Joined: 11-November 10
From: SoCal, USA


anything for firefighters, hon! we're all happy to help. :) tina

--------------------
"the wheel never stops turning"
Go to the top of the page
 
ADezii
post May 24 2019, 06:15 PM
Post#8



Posts: 2,395
Joined: 4-February 07
From: USA, Florida, Delray Beach


@esturgesjr:
Fire Fighting is what I did for over 32 years (1972 to 2005) in a major metropolitan area (USA). I also spent 15 years in a Hazardous Materials Unit. Quite a thrill, isn't it!
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    24th June 2019 - 08:33 PM