Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing a word document (Very Strange)

Status
Not open for further replies.

techu4

Technical User
Jun 27, 2005
32
GB
Hi all,

I have a for next loop running that has a case select section in it. If a case is found to be true the app tells an Act! database to genereate a letter using word.

I then need to print the letter. when i tell the the active document to print I get an error saying that there is no active document.

I have no idea as to why is says that there is no active document as i can see it in word.

Can anyone please help as this is making me pull my hair out.

Here is a snippet of the code:

Code:
'This sets up the Act! database object
Set objapp = CreateObject("ACTOLE.APPOBJECT")
Set objviews = objapp.Views
Set objC = objviews.Create(1, "CL")


Dim intX As Integer
  Dim WD As Object
Set WD = New Word.Application

    For intX = 1 To UBound(RowData) 'Rows dimension
    
......other code sits here
                
Select Case StatUs
                          
                    
                        Case "Input", "Sales Capture", "Awaiting Refer Sales Contact", "Awaiting Sales Contact", "Awaiting Quoting"
                       smsMessage = "Your recent Loan Application has been provisionally approved. Call us on 08704 428030, quoting your name & postcode so your loan can be arranged."
                        Call SendSmS
                       Case "Originals Pack Sent"
                       smsMessage = "Your signable documents have been sent out and should be with your in 48 hours."
                        Call SendSmS
                        Case "Awaiting Docs"
                       smsMessage = "We have not received your loan documents back. Please complete and return A.S.A.P"
                        Call SendSmS
                        Case "Advance Pack Sent"
                        objapp.Command 2300
                        Pause 7500 'sleep for 2.5 seconds
                        
                        On Error GoTo ActiveDoC
                        WD.ActiveDocument.PrintOut
                        
                                            
                        Pause 5000 'sleep for 2.5 seconds
                        WD.Application.Quit wdDoNotSaveChanges
Pause 2500
End Select

......other code sits here

Next intX
Set WD = Nothing

Thanks in advance

I hope i am not being really stupid and apologise if I am.

Cheers

Techu4
 
You don't say where the error happens. This doesn't look like where, though. What line causes your "no active document" error to occur?

Bob
 
Hi,

Sorry, its the line

WD.ActiveDocument.PrintOut

hope you can help.

Cheers

Techu4
 
Hi:

I am a bit confused. Why did you dimension WD as an Object and not as a Word.Application?



Cassie
PIII-500Mhz-128MB
Win98SE-VB6SP5
 
Hi:

Did you open a document in the Word Application? For example,
Code:
    WD.Documents.Add Template:= _
        "C:\WINDOWS\Application Data\Microsoft\Templates\Normal.dot", NewTemplate _
        :=False, DocumentType:=0


Cassie
PIII-500Mhz-128MB
Win98SE-VB6SP5
 
Hi,

I did not open the application, the line "objapp.Command 2300" actually kicks of word.

any ideas

Cheers
 
techu4,

The following code appears to demonstrate that individual instances of Word maintain individual ActiveDocuments;

'paste this into a new form; given a ref to a Word Object Lib
Private Sub Command1_Click()

Dim WD1 As Object
Set WD1 = New Word.Application
Dim WD2 As Object
Set WD2 = New Word.Application

WD1.Documents.Open App.Path & "\Doc1.doc"
WD2.Documents.Open App.Path & "\Doc2.doc"


Print WD1.ActiveDocument.Name
Print WD2.ActiveDocument.Name

WD2.Quit
WD1.Quit

Set WD1 = Nothing
Set WD2 = Nothing

End Sub

I suggest you have more than a single instance of Word running, one with an ActiveDocument started by your "Command 2003" the other with no ActiveDocument started by your "Set WD = New Word.Application".

Hugh,
 
Further to my previous, you should investigate use of GetObject as in the following;

Private Sub Command1_Click()

Dim WD1 As Object
Set WD1 = New Word.Application
Dim WD2 As Object
Set WD2 = New Word.Application

WD1.Documents.Open App.Path & "\Doc1.doc"
WD2.Documents.Open App.Path & "\Doc2.doc"

Print WD1.ActiveDocument.Name
Print WD2.ActiveDocument.Name

Dim WDoc As Object
Set WDoc = GetObject(App.Path & "\Doc1.doc")

Print WDoc.Application.ActiveDocument.Name

WD2.Quit
WD1.Quit

Set WD1 = Nothing
Set WD2 = Nothing
Set WDoc = Nothing

End Sub

Hugh,
 
I think the error is due to the fact that the word doc always run's in the bakround and never becomes active. you need to get a handle on this doc before you can print it.

Everybody body is somebodys Nutter.
 
Hi Chris,

When the doc is created by the database word posp up as the active window. Would this not make the document active.

If not do you know how to get a handle on the doc.

Cheers

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top