Repost: Creating an Outlook Task from MS Word 2000 
Author Message
 Repost: Creating an Outlook Task from MS Word 2000

I have reposted this as I have not had a response.

This is a follow on from thread on "Creating an Outlook Task from MS Word
2000"

(Thanks again Astrid for your help).

I have a table with columns that have the form fields I would like to
populate new tasks with, ie.

Table Heading:
Action Item    Responsibility            Due Date             Status
New row:
TaskItem1    TaskResponsibility1    TaskDueDate1
New row:
TaskItem2    TaskResponsibility2    TaskDueDate2
New row:
TaskItem3    TaskResponsibilty3    TaskDueDate3

and this goes on to form fields task* 15. Each row in the table would give
me the info I need to fill in a task form. So in theory I could end up with
15 tasks or only 5.

I can get the first row's info into a task with the code Astrid has kindly
given me as below:
With oNewTask
            .Assign
            .Subject = ActiveDocument.FormFields("TaskItem1").Result
            .Recipients.Add
Name:=ActiveDocument.FormFields("TaskResponsibility1").Result
            .Recipients.ResolveAll
            .DueDate = ActiveDocument.FormFields("TaskDateDue1").Result
          End With

But I am not sure of the best way to go about getting new tasks for each
row. I could create code 15 times to capture each rows info and create 15
tasks. But I do not want to create a task if the result of any "TaskItem*"
form field is blank.

Can I count Form Fields and say If  any "TaskItem" form field is blank go to
next "Task Item" form field? Or can you GoTo rows and then run a macro to
see if the "Task Item" form field is blank and if it is GoTo next row.

Any thoughts? I hope this makes sense.

Regards
Vera Hawkins


Quote:
> Hi Vera,

> That's not so difficult:

>     ActiveDocument.Formfields("NameOfFormfield").Result

> will give you the entered text from the formfield.

> So try something like:
>     With oNewTask
>         .Subject = ActiveDocument.Formfields("NameSubjectField").Result
> etc.

> Hope this helps,
> regards,
> Astrid

> Please post replies to the newsgroup so that other readers can contribute
or
> benefit.

> Visit the MVP Word FAQ site at http://www.*-*-*.com/
> For direct access to all Microsoft newsgroups:



> > Thanks Astrid,

> > Your code is very helpful.

> > I now need to get the results of Word's form fields into the:

> > .Subject
> > .Recipients
> > .DueDate

> > part of the code. This will test my brain!!

> > Regards
> > Vera



Tue, 17 Jun 2003 13:15:08 GMT  
 Repost: Creating an Outlook Task from MS Word 2000
Hi Vera,

I didn't forget you ;-)

You need to know that all the people answering questions in these newsgroups
are volunteers. Sometimes when you don't get an answer it means that nobody
knows the answer in which case it might be a good idea to supply some more
info on a reply to your original post (do not create a new post since this
is only causing confusion)
Sometimes people ask more then one question in a post. Splitting up your
questions can also help in getting a response earlier.

In this particular case - speeking for myself of course - I needed some time
to figure this out. I had to create the code on another system then the one
where I'm currently working on and needed some time to think out of - what I
think - is the best approach to handle this. This is why it did take me some
time to answer you.

You can paste the following code in one entire module. It's separated in a
few procedures:

- ReadTableFormFields() which reads the formfields row by row in your table
(note that I assumed that the table that contains the formfields is the
first table in the document and the formfields are in column 1, column 2 and
column 3)

The first thing this routine does is to start Outlook.
Then it processes the table, row by row and reads any formfields in column1,
column2 and column3 for Subject, Recipient and DueDate
After that it calls another procedure WriteOutlookTask which takes the
subject, recipient and date from the formfields as arguments and writes a
new task based on these arguments.
It does this for every row with formfields.

Once it's finished, it closes Outlook (if it was started in one of these
macros)

I've added some comments in the code but please feel free to ask if you need
any additional info.

--------------------------------------------------------
Option Explicit
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oNameSpace As Outlook.NameSpace

Sub ReadTableFormFields()
Dim oCell As Cell
Dim oTable As Table
Dim oFormfield As FormField
Dim oRow As Row
Dim sFormSubject As String
Dim sFormRecipient As String
Dim dFormDate As Date

  'First start Outlook
  StartOutlook

  'If your table is not the first table
  'in the document, replace the .Tables(1)
  'with the index of your table
  Set oTable = ActiveDocument.Tables(1)
  'Loop through all the rows in the table
  For Each oRow In oTable.Rows
    'Check if there are formfields in this
    'row of the table
    If oRow.Range.FormFields.Count > 0 Then
      sFormSubject = oRow.Cells(1).Range.FormFields(1).Result
      sFormRecipient = oRow.Cells(2).Range.FormFields(1).Result
      'You need to convert the date to a date variable
      'with cdate(sText)
      dFormDate = CDate(oRow.Cells(3).Range.FormFields(1).Result)
      'Create the task
      WriteOutlookTask sSubject:=sFormSubject, dDueDate:=dFormDate, _
                                 sRecipient:=sFormRecipient
    End If
  Next

  'Close Outlook
  CloseOutlook
End Sub

Function StartOutlook() As Boolean
  On Error Resume Next
  Set oOutlookApp = GetObject(, "Outlook.Application")
  If Err <> 0 Then
    Set oOutlookApp = CreateObject("Outlook.Application")
    bStarted = True
  End If
  Set oNameSpace = oOutlookApp.GetNamespace("MAPI")
End Function

Sub CloseOutlook()
  'Only close Outlook if we started
  'it programmatically
  If bStarted Then oOutlookApp.Quit
  Set oNameSpace = Nothing
  Set oOutlookApp = Nothing
End Sub

Sub WriteOutlookTask(sSubject As String, dDueDate As Date, _
                     sRecipient As String)
Dim oNewTask As Outlook.TaskItem

  Set oNewTask =
oNameSpace.GetDefaultFolder(olFolderOutbox).Items.Add(olTaskItem)

  With oNewTask
    .Assign
    .Subject = sSubject
    .Recipients.Add Name:=sRecipient
    .Recipients.ResolveAll
    .DueDate = dDueDate
    .Save
  End With
  oNewTask.Send

  Set oNewTask = Nothing

End Sub
--------------------------------------------------------

Hope this helps,
regards,
Astrid

Please post replies to the newsgroup so that other readers can contribute or
benefit.

Visit the MVP Word FAQ site at http://www.mvps.org/word/
For direct access to all Microsoft newsgroups:



Quote:
> I have reposted this as I have not had a response.

> This is a follow on from thread on "Creating an Outlook Task from MS Word
> 2000"

> (Thanks again Astrid for your help).

> I have a table with columns that have the form fields I would like to
> populate new tasks with, ie.

> Table Heading:
> Action Item    Responsibility            Due Date             Status
> New row:
> TaskItem1    TaskResponsibility1    TaskDueDate1
> New row:
> TaskItem2    TaskResponsibility2    TaskDueDate2
> New row:
> TaskItem3    TaskResponsibilty3    TaskDueDate3

> and this goes on to form fields task* 15. Each row in the table would give
> me the info I need to fill in a task form. So in theory I could end up
with
> 15 tasks or only 5.

> I can get the first row's info into a task with the code Astrid has kindly
> given me as below:
> With oNewTask
>             .Assign
>             .Subject = ActiveDocument.FormFields("TaskItem1").Result
>             .Recipients.Add
> Name:=ActiveDocument.FormFields("TaskResponsibility1").Result
>             .Recipients.ResolveAll
>             .DueDate = ActiveDocument.FormFields("TaskDateDue1").Result
>           End With

> But I am not sure of the best way to go about getting new tasks for each
> row. I could create code 15 times to capture each rows info and create 15
> tasks. But I do not want to create a task if the result of any "TaskItem*"
> form field is blank.

> Can I count Form Fields and say If  any "TaskItem" form field is blank go
to
> next "Task Item" form field? Or can you GoTo rows and then run a macro to
> see if the "Task Item" form field is blank and if it is GoTo next row.

> Any thoughts? I hope this makes sense.

> Regards
> Vera Hawkins



> > Hi Vera,

> > That's not so difficult:

> >     ActiveDocument.Formfields("NameOfFormfield").Result

> > will give you the entered text from the formfield.

> > So try something like:
> >     With oNewTask
> >         .Subject = ActiveDocument.Formfields("NameSubjectField").Result
> > etc.

> > Hope this helps,
> > regards,
> > Astrid

> > Please post replies to the newsgroup so that other readers can
contribute
> or
> > benefit.

> > Visit the MVP Word FAQ site at http://www.mvps.org/word/
> > For direct access to all Microsoft newsgroups:



> > > Thanks Astrid,

> > > Your code is very helpful.

> > > I now need to get the results of Word's form fields into the:

> > > .Subject
> > > .Recipients
> > > .DueDate

> > > part of the code. This will test my brain!!

> > > Regards
> > > Vera



Wed, 18 Jun 2003 05:22:12 GMT  
 Repost: Creating an Outlook Task from MS Word 2000
I do apologise for my hastiness. The time and energy the people spend to answer questions is really fantastic and I do appreciate
it.

Thanks again for your help.

I hope that you all have a great New Year.

Regards
Vera Hawkins

| Hi Vera,
|
| I didn't forget you ;-)
|
| You need to know that all the people answering questions in these newsgroups
| are volunteers. Sometimes when you don't get an answer it means that nobody
| knows the answer in which case it might be a good idea to supply some more
| info on a reply to your original post (do not create a new post since this
| is only causing confusion)
| Sometimes people ask more then one question in a post. Splitting up your
| questions can also help in getting a response earlier.
|
| In this particular case - speeking for myself of course - I needed some time
| to figure this out. I had to create the code on another system then the one
| where I'm currently working on and needed some time to think out of - what I
| think - is the best approach to handle this. This is why it did take me some
| time to answer you.
|
| You can paste the following code in one entire module. It's separated in a
| few procedures:
|
| - ReadTableFormFields() which reads the formfields row by row in your table
| (note that I assumed that the table that contains the formfields is the
| first table in the document and the formfields are in column 1, column 2 and
| column 3)
|
| The first thing this routine does is to start Outlook.
| Then it processes the table, row by row and reads any formfields in column1,
| column2 and column3 for Subject, Recipient and DueDate
| After that it calls another procedure WriteOutlookTask which takes the
| subject, recipient and date from the formfields as arguments and writes a
| new task based on these arguments.
| It does this for every row with formfields.
|
| Once it's finished, it closes Outlook (if it was started in one of these
| macros)
|
| I've added some comments in the code but please feel free to ask if you need
| any additional info.
|
| --------------------------------------------------------
| Option Explicit
| Dim bStarted As Boolean
| Dim oOutlookApp As Outlook.Application
| Dim oNameSpace As Outlook.NameSpace
|
| Sub ReadTableFormFields()
| Dim oCell As Cell
| Dim oTable As Table
| Dim oFormfield As FormField
| Dim oRow As Row
| Dim sFormSubject As String
| Dim sFormRecipient As String
| Dim dFormDate As Date
|
|   'First start Outlook
|   StartOutlook
|
|   'If your table is not the first table
|   'in the document, replace the .Tables(1)
|   'with the index of your table
|   Set oTable = ActiveDocument.Tables(1)
|   'Loop through all the rows in the table
|   For Each oRow In oTable.Rows
|     'Check if there are formfields in this
|     'row of the table
|     If oRow.Range.FormFields.Count > 0 Then
|       sFormSubject = oRow.Cells(1).Range.FormFields(1).Result
|       sFormRecipient = oRow.Cells(2).Range.FormFields(1).Result
|       'You need to convert the date to a date variable
|       'with cdate(sText)
|       dFormDate = CDate(oRow.Cells(3).Range.FormFields(1).Result)
|       'Create the task
|       WriteOutlookTask sSubject:=sFormSubject, dDueDate:=dFormDate, _
|                                  sRecipient:=sFormRecipient
|     End If
|   Next
|
|   'Close Outlook
|   CloseOutlook
| End Sub
|
| Function StartOutlook() As Boolean
|   On Error Resume Next
|   Set oOutlookApp = GetObject(, "Outlook.Application")
|   If Err <> 0 Then
|     Set oOutlookApp = CreateObject("Outlook.Application")
|     bStarted = True
|   End If
|   Set oNameSpace = oOutlookApp.GetNamespace("MAPI")
| End Function
|
| Sub CloseOutlook()
|   'Only close Outlook if we started
|   'it programmatically
|   If bStarted Then oOutlookApp.Quit
|   Set oNameSpace = Nothing
|   Set oOutlookApp = Nothing
| End Sub
|
|
| Sub WriteOutlookTask(sSubject As String, dDueDate As Date, _
|                      sRecipient As String)
| Dim oNewTask As Outlook.TaskItem
|
|   Set oNewTask =
| oNameSpace.GetDefaultFolder(olFolderOutbox).Items.Add(olTaskItem)
|
|   With oNewTask
|     .Assign
|     .Subject = sSubject
|     .Recipients.Add Name:=sRecipient
|     .Recipients.ResolveAll
|     .DueDate = dDueDate
|     .Save
|   End With
|   oNewTask.Send
|
|   Set oNewTask = Nothing
|
| End Sub
| --------------------------------------------------------
|
| Hope this helps,
| regards,
| Astrid
|
| Please post replies to the newsgroup so that other readers can contribute or
| benefit.
|
| Visit the MVP Word FAQ site at http://www.mvps.org/word/
| For direct access to all Microsoft newsgroups:

|
|


| > I have reposted this as I have not had a response.
| >
| > This is a follow on from thread on "Creating an Outlook Task from MS Word
| > 2000"
| >
| > (Thanks again Astrid for your help).
| >
| > I have a table with columns that have the form fields I would like to
| > populate new tasks with, ie.
| >
| > Table Heading:
| > Action Item    Responsibility            Due Date             Status
| > New row:
| > TaskItem1    TaskResponsibility1    TaskDueDate1
| > New row:
| > TaskItem2    TaskResponsibility2    TaskDueDate2
| > New row:
| > TaskItem3    TaskResponsibilty3    TaskDueDate3
| >
| > and this goes on to form fields task* 15. Each row in the table would give
| > me the info I need to fill in a task form. So in theory I could end up
| with
| > 15 tasks or only 5.
| >
| > I can get the first row's info into a task with the code Astrid has kindly
| > given me as below:
| > With oNewTask
| >             .Assign
| >             .Subject = ActiveDocument.FormFields("TaskItem1").Result
| >             .Recipients.Add
| > Name:=ActiveDocument.FormFields("TaskResponsibility1").Result
| >             .Recipients.ResolveAll
| >             .DueDate = ActiveDocument.FormFields("TaskDateDue1").Result
| >           End With
| >
| > But I am not sure of the best way to go about getting new tasks for each
| > row. I could create code 15 times to capture each rows info and create 15
| > tasks. But I do not want to create a task if the result of any "TaskItem*"
| > form field is blank.
| >
| > Can I count Form Fields and say If  any "TaskItem" form field is blank go
| to
| > next "Task Item" form field? Or can you GoTo rows and then run a macro to
| > see if the "Task Item" form field is blank and if it is GoTo next row.
| >
| > Any thoughts? I hope this makes sense.
| >
| > Regards
| > Vera Hawkins
| >


| > > Hi Vera,
| > >
| > > That's not so difficult:
| > >
| > >     ActiveDocument.Formfields("NameOfFormfield").Result
| > >
| > > will give you the entered text from the formfield.
| > >
| > > So try something like:
| > >     With oNewTask
| > >         .Subject = ActiveDocument.Formfields("NameSubjectField").Result
| > > etc.
| > >
| > >
| > > Hope this helps,
| > > regards,
| > > Astrid
| > >
| > > Please post replies to the newsgroup so that other readers can
| contribute
| > or
| > > benefit.
| > >
| > > Visit the MVP Word FAQ site at http://www.mvps.org/word/
| > > For direct access to all Microsoft newsgroups:

| > >
| > >


| > > > Thanks Astrid,
| > > >
| > > > Your code is very helpful.
| > > >
| > > > I now need to get the results of Word's form fields into the:
| > > >
| > > > .Subject
| > > > .Recipients
| > > > .DueDate
| > > >
| > > > part of the code. This will test my brain!!
| > > >
| > > > Regards
| > > > Vera
| >
| >
| >
| >
|
|



Wed, 18 Jun 2003 06:02:15 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Final answer: Creating an Outlook Task from MS Word 2000

2. Creating an Outlook Task from MS Word 2000

3. Find Tasks created from MS Project 2000 in Outlook 2000

4. Access 2000 append query run from Outlook 2000 fails - no error message - REPOST

5. Calling MS-Word from button event click on outlook 98/2000

6. Linking Access 2000 Table to Outlook 2000 Tasks

7. Create task's in MS Outlook from VB4.0 application

8. Create task's in MS Outlook from VB4.0 application

9. Question regarding MAPI, MS Outlook 2000, and Outlook Express 6

10. MS PJ 2000 and MS Word via VBA

11. Outlook 2000 to Word 2000 document merge problem

12. Problem with Tasks and localized Outlook 2000

 

 
Powered by phpBB® Forum Software