Solved

MS Access Print doc onclick

Posted on 2011-03-20
15
339 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
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.

 

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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