Solved

MS Access Print doc onclick

Posted on 2011-03-20
15
338 Views
Last Modified: 2012-05-11
here below i have a code that i am using onclick of a command button. what i want to know is on Case 2 can i add a inputbox to say amount of copies i want to print? right now it just prints out one copy

Private Sub Command175_Click()
Dim varResponse As Variant
Dim strMenu As String

strMenu = "1. Tow-away form Preview" & vbCr & vbCr

strMenu = strMenu & "2. Print Tow-away form (1 copy) " & vbCr & vbCr

strMenu = strMenu & "3. Exit"

varResponse = ""
Do While Len(varResponse) = 0 Or varResponse < 1 Or varResponse > 3
    varResponse = InputBox(strMenu, "Tow-away form print options", 1)
Loop

Select Case varResponse
    Case 1
    Dim oApp As Object
    Dim strDocName As String
   
   strDocName = DLookup("TowAwayFormLocation", "tblCompanyInformation", "[CompanyID] = 1")
   
   Set oApp = CreateObject("Word.Application")
   oApp.Visible = True
   oApp.Documents.Open strDocName
    Case 2
    Dim WordObj As Object
   Set WordObj = CreateObject("Word.Application")
   WordObj.Documents.Open DLookup("TowAwayFormLocation", "tblCompanyInformation", "[CompanyID] = 1")
   WordObj.PrintOut Background:=False
   WordObj.Quit
   Set WordObj = Nothing
    Case 3
        Exit Sub
End Select


End Sub

Open in new window


0
Comment
Question by:Blueice13085
  • 9
  • 6
15 Comments
 
LVL 23

Expert Comment

by:OP_Zaharin
ID: 35177835
-to specify number of copies:

WordObj.FilePrint Background:=0, AppendPrFile:=0, Range:=0, _
      PrToFileName:="", From:="", To:="", Type:=0, NumCopies:=2
0
 
LVL 23

Expert Comment

by:OP_Zaharin
ID: 35177856
-if you are using Word 97, use the the following code instead:

WordObj.PrintOut Background:=False, Copies:=2
0
 

Author Comment

by:Blueice13085
ID: 35177871
tried to do this

Dim WordObj As Object
    Dim NCopies As String
    NCopies = InputBox("Please Enter Number of Copies to Print.", "Qty to Print!", 1)
   Set WordObj = CreateObject("Word.Application")
   WordObj.Documents.Open DLookup("TowAwayFormLocation", "tblCompanyInformation", "[CompanyID] = 1")
   WordObj.PrintOut Background:=False, Copies:=NCopies
   WordObj.Quit
   Set WordObj = Nothing

Open in new window


only thing that does is print one copy still, and using A2003
0
 

Author Comment

by:Blueice13085
ID: 35177876
when the input box comes up i press 2 and still only prints one
any ideas?
0
 
LVL 23

Expert Comment

by:OP_Zaharin
ID: 35177888
- declare NCopies as integer instead:

Dim NCopies As Integer
0
 

Author Comment

by:Blueice13085
ID: 35177901
Still only prints one copy,even if i use the Copies:=2 still only shows one page to print
0
 
LVL 23

Expert Comment

by:OP_Zaharin
ID: 35177926
1-alternatively, you can put the print module into a function:

Public Function PrintDoc(FileName)
    Dim WordObj As Object

   Set WordObj = CreateObject("Word.Application")
   WordObj.Documents.Open DLookup("TowAwayFormLocation", "tblCompanyInformation", "[CompanyID] = 1")
   WordObj.PrintOut Background:=False
   WordObj.Quit
   Set WordObj = Nothing
End Function

2- then create a print button and put the following codes which call the print function in a loop:

Dim NCopies as integer
Dom Copies as integer

NCopies = InputBox("Please Enter Number of Copies to Print.", "Qty to Print!", 1)

For copies = 1 to NCopies
      PrintDoc("Full Path to the file")
Next copies
0
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)

 
LVL 23

Expert Comment

by:OP_Zaharin
ID: 35177933
- you need to do a bit of code tuning there as the sample i used if you have a file to print. sorry about that
0
 
LVL 23

Accepted Solution

by:
OP_Zaharin earned 500 total points
ID: 35177947
- try this instead:

Dim WordObj As Object
    Dim NCopies As integer
    Dim Copies As integer

    NCopies = InputBox("Please Enter Number of Copies to Print.", "Qty to Print!", 1)
   Set WordObj = CreateObject("Word.Application")
   WordObj.Documents.Open DLookup("TowAwayFormLocation", "tblCompanyInformation", "[CompanyID] = 1")

      For Copies = 1 to NCopies
            WordObj.PrintOut Background:=False
      Next Copies

   WordObj.Quit
   Set WordObj = Nothing

Open in new window

0
 

Author Comment

by:Blueice13085
ID: 35177960
im not understanding what you are trying to explain to me here?
0
 
LVL 23

Expert Comment

by:OP_Zaharin
ID: 35177973
- ignore my comment on ID35177926.
- what I'm trying to explain in my comment on ID: 35177947, is to loop the printing command "WordObj.PrintOut" (since the Copies:= didn't work for you)
0
 

Author Comment

by:Blueice13085
ID: 35177976
This code works


Dim WordObj As Object
    Dim NCopies As integer
    Dim Copies As integer

    NCopies = InputBox("Please Enter Number of Copies to Print.", "Qty to Print!", 1)
   Set WordObj = CreateObject("Word.Application")
   WordObj.Documents.Open DLookup("TowAwayFormLocation", "tblCompanyInformation", "[CompanyID] = 1")

      For Copies = 1 to NCopies
            WordObj.PrintOut Background:=False
      Next Copies

   WordObj.Quit
   Set WordObj = Nothing



but i am guessing this would be the only way is to make it print 3 different times? tiring to get it to show as Pages 2..., sense this is used in a heavy office environment and printing is done by multiple people
0
 
LVL 23

Expert Comment

by:OP_Zaharin
ID: 35177994
- yes you are right. the loop is actually sending a print command 3 times instead of supplying the information to print it 3 copies.

- can you try to change the  "WordObj.PrintOut Background:=False" to "WordObj.PrintOut Copies:=NCopies" to see if it works.
- and also remark the "For-loop" and "Dim Copies As integer"
0
 

Author Comment

by:Blueice13085
ID: 35178026
nope that didn't work either, but thanks for trying, i will how ever accept your solution sense it does do what i ask:)
0
 
LVL 23

Expert Comment

by:OP_Zaharin
ID: 35178054
- glad it works for you. thank you Blueice :)
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

929 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

10 Experts available now in Live!

Get 1:1 Help Now