Results 1 to 8 of 8
  1. #1
    Join Date
    Sep 2004
    Location
    Tampa, FL
    Posts
    520

    Unanswered: Print a folder full of Docs.

    I have an Access 2k DB. When a new client is put into the system they must sign and date about 20 forms. ( no exageration.) so I have the following code to print out these docs attached to a buton on the intake form.
    Code:
    Private Sub Command52_Click()
    
    Dim WordObj As Object
       Set WordObj = CreateObject("Word.Application")
    'here lies the problem
       WordObj.Documents.Open "C:\rezdb\PAS\ed.doc"
       WordObj.PrintOut Background:=False
       WordObj.Quit
       Set WordObj = Nothing
    End Sub
    Please note the location is simply for testing before going live.

    If I use the name of a single Doc it prints wonderfully.
    However, as stated there are about 20 Doc files to print. if I use *.Doc i get a runtime error 5151.

    How could I modify this to print all the Word docs in the folder?

    Easy Answer #1 make all the Docs 1 doc. Can not do that as the Real application will be used in about 15 different offices each using different docs in thier intake process.

    Thanks,
    Last edited by Darasen; 11-17-04 at 11:27.
    Darasen

  2. #2
    Join Date
    Sep 2004
    Posts
    161
    you can try this
    Code:
    Sub test()
    Dim db  As String
    db = Dir("C:\rezdb\PAS\*.doc")
    Do Until db = ""
       WordObj.Documents.Open "C:\rezdb\PAS\" & db
       WordObj.PrintOut Background:=False
       WordObj.Quit
       Set WordObj = Nothing
    db=Dir
    Loop
    End Sub
    In code we trust

  3. #3
    Join Date
    Sep 2004
    Location
    Tampa, FL
    Posts
    520
    Thanks for the reply unfortunately it does not work I get an error on this line.

    WordObj.Documents.Open "C:\rezdb\PAS\" & db

    Runtime Error 424 Object Required.
    Darasen

  4. #4
    Join Date
    Sep 2004
    Posts
    161
    Try to concatenate the path and the file name
    dim fileName a sString
    fileName="C:\Path\" & db
    WordObj.Documents.Open fileName
    In code we trust

  5. #5
    Join Date
    Sep 2004
    Posts
    161
    To complete my idea, i have try this code
    Code:
    Sub test()
    Dim db  As String
    Dim filename As String
    Dim Wrd As Word.Application
    Dim PrintDoc As Word.Document
    
    Dim WordObj As Object
    
        On Error Resume Next
        Set Wrd = GetObject(, "Word.Application")
        If Err.Number <> 0 Then
            Set Wrd = CreateObject("Word.Application")
        End If
        On Error GoTo 0
    
        db = Dir("D:\JEPI\Word\*.doc")
        Do Until db = ""
            filename = "D:\JEPI\Word\" & db
            Wrd.Documents.Open filename
            Set PrintDoc = ActiveDocument
            PrintDoc.PrintOut Background:=False
            PrintDoc.Close
            db = Dir
        Loop
        Wrd.Quit
        Set Wrd = Nothing
        
    End Sub
    In code we trust

  6. #6
    Join Date
    Sep 2004
    Posts
    161
    To complete my idea, i have try this code
    Code:
    Sub test()
    Dim db  As String
    Dim filename As String
    Dim Wrd As Word.Application
    Dim PrintDoc As Word.Document
    
    Dim WordObj As Object
    
        On Error Resume Next
        Set Wrd = GetObject(, "Word.Application")
        If Err.Number <> 0 Then
            Set Wrd = CreateObject("Word.Application")
        End If
        On Error GoTo 0
    
        db = Dir("D:\JEPI\Word\*.doc")
        Do Until db = ""
            filename = "D:\JEPI\Word\" & db
            Wrd.Documents.Open filename
            Set PrintDoc = ActiveDocument
            PrintDoc.PrintOut Background:=False
            PrintDoc.Close
            db = Dir
        Loop
        Wrd.Quit
        Set Wrd = Nothing
        
    End Sub
    But you must have a reference to Words in Access
    In code we trust

  7. #7
    Join Date
    Sep 2004
    Location
    Tampa, FL
    Posts
    520
    Many thanks that works like a charm . Now I shall look at it closely to figure out exactly why it works .
    Darasen

  8. #8
    Join Date
    Sep 2004
    Posts
    161
    Just one thing to simplify
    Dim PrintDoc As Word.Document is not necessary
    You can use directly
    ActiveDocument.printout
    ActiveDocument.close
    In code we trust

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •