Custom Task form cmd button runs once

B

Bob S

Hi-
I'm building a custom task form (p.2 below)that has text
boxes and a command button. When I press the command
button I want the text from the text boxes (txt1, for
example)to go to certian spots on a word document
(test.doc with booksmarks). I got it to work using the
following code:

Sub CMDOpenWD_Click

Dim objWord 'As Word.Application

Dim objDoc 'As Word.Document

Dim objSelect 'As Word.Selection

Dim objDocItem 'As DocumentItem

dim control 'As outlook control

dim formpage 'As page

Set FormPage = Item.GetInspector.ModifiedFormPages("P.2")

Set control = formpage.controls("txt1")

Set objWord = CreateObject("Word.Application")

Set objDoc = objWord.Documents.open("C:\test.doc" )

Set objSelect = objWord.Selection

'msgbox objdoc.Bookmarks.count'sanity check one

objSelect.TypeText control.text

'Msgbox control.text'sanity check two

objword.visible = true

objdoc.application.printout

Msgbox "File printing"

Set objWord = Nothing

Set objdoc = nothing

End Sub

But the code doesn't work after I send the task or after
I close & save the task. It works fine when I first open
the form or "run this form" from the design page. How do
I get the code to work all the time?

Any help is appreciated
Bob
 
G

Guest

I'm using outlook 2003 & 2000. I tried it on 2 version
on 2 different computers.

Published in personal forms library in both cases.

Bob
 
B

Bob S

I'm using outlook 2003 & 2000. I tried it on 2 version
on 2 different computers.

Published in personal forms library in both cases.

Bob
 
S

Sue Mosher [MVP-Outlook]

The symptoms indicate that the form is becoming one-off (see
http://www.outlookcode.com/d/formpub.htm#oneoff). There are many possible
causes. Do you have other code in the form?
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top