Solved

MS Access Print doc onclick

Posted on 2011-03-20
15
337 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
Comment Utility
-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
Comment Utility
-if you are using Word 97, use the the following code instead:

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

Author Comment

by:Blueice13085
Comment Utility
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
Comment Utility
when the input box comes up i press 2 and still only prints one
any ideas?
0
 
LVL 23

Expert Comment

by:OP_Zaharin
Comment Utility
- declare NCopies as integer instead:

Dim NCopies As Integer
0
 

Author Comment

by:Blueice13085
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 23

Expert Comment

by:OP_Zaharin
Comment Utility
- 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
Comment Utility
- 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
Comment Utility
im not understanding what you are trying to explain to me here?
0
 
LVL 23

Expert Comment

by:OP_Zaharin
Comment Utility
- 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
Comment Utility
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
Comment Utility
- 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
Comment Utility
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
Comment Utility
- glad it works for you. thank you Blueice :)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 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

11 Experts available now in Live!

Get 1:1 Help Now