?
Solved

MS Access Print doc onclick

Posted on 2011-03-20
15
Medium Priority
?
349 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
[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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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 2000 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

777 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