Solved

MS Access Print doc onclick

Posted on 2011-03-20
15
341 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

792 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