Lotus Notes - add calendar entry

Experts,

The below code does work however the Subject and the Const Positioin (the time of appt) are hard coded.  

I want the Lotus Notes code to work in conjunction with a Tasks form I have.  
It works with Outlook but we are changing to Lotus Notes :(

I will post the Lotus Notes code and the Outlook code (much simpler) in hopes of being able to modify the LN code according to what record I am on in the Tasks Form.  

I will need the Start Date, Title, Due Date to be populated in Lotus Notes (all according to the record I am presently on in the Tasks Form.

Hope that makes sense.  Please ask if need additional information.


Private Sub cmdLotusNotes_Click()

    Const Subject = "September staff meeting (Tuesday the ninth)"
    Const position = "9/9/2009 10:00 AM"
    Dim s As New NotesSession
    Call s.Initialize("notes")
   '     s.Initialize
    Dim dir As NotesDbDirectory
    Dim db As NotesDatabase
    Set dir = s.GetDbDirectory("")
    Set db = dir.OpenMailDatabase
    MsgBox db.Title & " on " & db.Server, , db.FilePath
    Dim doc As Object 'notesDocument
    Set doc = db.createDocument
    doc.replaceItemvalue "Form", "Appointment"
    Dim dateTime As Object 'NotesDateTime
    Set dateTime = s.createDateTime(position)
    doc.replaceItemvalue "$Alarm", 1
    doc.replaceItemvalue "$AlarmOffset", 0
    MsgBox "Setting reminder/alarm - " & dateTime.lslocalTime & " - " & Subject
    doc.replaceItemvalue "startDateTime", dateTime
    doc.replaceItemvalue "endDateTime", dateTime
    doc.replaceItemvalue "calendarDateTime", dateTime
    doc.replaceItemvalue "Subject", Subject
    doc.replaceItemvalue "startTime", dateTime
    doc.replaceItemvalue "appointmentType", "3"
    doc.replaceItemvalue "Alarms", "1"
    doc.replaceItemvalue "startDate", dateTime
    doc.replaceItemvalue "endDate", dateTime
    doc.replaceItemvalue "endTime", dateTime
    doc.Save True, True
    doc.putInFolder "($Alarms)"

Open in new window

pdvsaProject financeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pdvsaProject financeAuthor Commented:
here is the Outlook Code


Private Sub cmdAddOutlookTask_Click()

With Me.[tasks subform].Form
       If AddOutlookTask(![StartDate], ![Title], ![DueDate], 8) Then
               MsgBox "The task was added to Outlook"
    End If
   End With

End Sub

Open in new window

0
Sjef BosmanGroupware ConsultantCommented:
Sorry, don't quite understand what you want from us.

Guessing:

Function AddNotesTask(StartDate, Title, DueDate) As Integer
:
here your code, you replace the consts by the parameters in the function definition
:
etc.
0
pdvsaProject financeAuthor Commented:
Sjef: thanks for tbe response.  

Allow me to summarize :
i have a form in continous forms mode
this for is a Tasks Form
it has Subject, Start Date, end Date
i want to add the task to LN just as i did in OL

that is a short summary

the LN code above has the Subject and Start Date hard coded and therefore the LN code does not help because it adds a cAlendar entry according to the hard coded info in the code.  I need to be according to my data on the tasks form.

Hope that helps.... Let me know what you think is next  
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

pdvsaProject financeAuthor Commented:
You can see that the OL code uses Me and i Am looking for something similar in the LN code. (to move away from the hard code in LN).  Sorta like making the LN code more flexible, dynamic.  I tbink the LN code adds a 2009 calendar entry.
0
Sjef BosmanGroupware ConsultantCommented:
Apparently you have some function called AddOutlookTask, right?

Just create a similar function AddNotesTask that contains most of the code above. Which language has this to be in? I only know LotusScript, but it looks like VB so it should probably be readable to you. The code below is a mixture of those languages, I'm afraid...

Function AddNotesTask(StartDate As String, Subject As String, DueDate As String) As Integer
    Dim s As New NotesSession
    Call s.Initialize("notes")
   '     s.Initialize
    Dim dir As NotesDbDirectory
    Dim db As NotesDatabase
    Set dir = s.GetDbDirectory("")
    Set db = dir.OpenMailDatabase
    MsgBox db.Title & " on " & db.Server, , db.FilePath
    Dim doc As Object 'notesDocument
    Set doc = db.createDocument
    doc.replaceItemvalue "Form", "Appointment"
    Dim dateTime As Object 'NotesDateTime
    Set dateTime = s.createDateTime(StartDate)
    Dim duedateTime As Object 'NotesDateTime
    Set duedateTime = s.createDateTime(DueDate)
    doc.replaceItemvalue "$Alarm", 1
    doc.replaceItemvalue "$AlarmOffset", 0
    MsgBox "Setting reminder/alarm - " & dateTime.lslocalTime & " - " & Subject
    doc.replaceItemvalue "startDateTime", dateTime
    doc.replaceItemvalue "endDateTime", duedateTime
    doc.replaceItemvalue "calendarDateTime", dateTime
    doc.replaceItemvalue "Subject", Subject
    doc.replaceItemvalue "startTime", dateTime
    doc.replaceItemvalue "appointmentType", "3"
    doc.replaceItemvalue "Alarms", "1"
    doc.replaceItemvalue "startDate", dateTime
    doc.replaceItemvalue "endDate", duedateTime
    doc.replaceItemvalue "endTime", duedateTime
    doc.Save True, True
    doc.putInFolder "($Alarms)"
End Sub
0
pdvsaProject financeAuthor Commented:
Sjef:  I did not notice that I had a function for the OL task.  I was wondering why the code looked so simple.  I am quite lost when I get into the code behind forms.  

I do have the OL function now...
since I will use the LN code above do you see any conflicts now knowing the OL function code below?  

thank you...will be back after a few hours... really appreciate the help.

Public Function AddOutlookTask( _
    StartDate As Date, _
    Subject As String, _
    Optional DueDate As Date, _
    Optional ReminderHours As Double, _
    Optional Body As String _
  ) As Boolean
Const olTaskItem As Long = 3
Dim olkApp As Object
Dim olkTask As Object
On Error GoTo ProcErr
  Set olkApp = CreateObject("Outlook.Application")
  Set olkTask = olkApp.CreateItem(olTaskItem)
  With olkTask
    .StartDate = StartDate
    If DueDate <> 0 Then
      .DueDate = DueDate
    End If
    If ReminderHours <> 0 Then
      ' set reminder the given number or hours before the start time
      .ReminderTime = DateAdd("n", -(ReminderHours * 60), StartDate)
      .ReminderSet = True
    End If
    .Subject = Subject
    .Body = Body
    .Save
  End With
  AddOutlookTask = True
ProcEnd:
  On Error Resume Next
  If Not olkTask Is Nothing Then Set olkTask = Nothing
  If Not olkApp Is Nothing Then Set olkApp = Nothing
  Exit Function
ProcErr:
  MsgBox Err.Description, vbExclamation, "Error adding Outlook task"
  Resume ProcEnd
End Function
0
pdvsaProject financeAuthor Commented:
Not sure if the option is in LN code, but if possible would like for a reminder a set number of minutes before the event triggers in LN.  I have learned this to be an important feature because many of the people that send me calendar entries in LN do not seet upa  reminder in their note and therefore it is easy to miss the meeting/event.
0
Sjef BosmanGroupware ConsultantCommented:
Now I'm confused... Where do you want to run this code? In Notes, or in some VB or VBA environment?

Function AddNotesTask(StartDate As String, Subject As String, DueDate As String, ReminderHours As Double) As Integer
    Dim s As New NotesSession
    Call s.Initialize("notes")
   '     s.Initialize
    Dim dir As NotesDbDirectory
    Dim db As NotesDatabase
    Set dir = s.GetDbDirectory("")
    Set db = dir.OpenMailDatabase
    MsgBox db.Title & " on " & db.Server, , db.FilePath
    Dim doc As Object 'notesDocument
    Set doc = db.createDocument
    doc.replaceItemvalue "Form", "Appointment"
    Dim dateTime As Object 'NotesDateTime
    Set dateTime = s.createDateTime(StartDate)
    Dim duedateTime As Object 'NotesDateTime
    Set duedateTime = s.createDateTime(DueDate)
    doc.replaceItemvalue "$Alarm", 1
    doc.replaceItemvalue "$AlarmOffset", - 60 * ReminderHours
    MsgBox "Setting reminder/alarm - " & dateTime.lslocalTime & " - " & Subject
    doc.replaceItemvalue "startDateTime", dateTime
    doc.replaceItemvalue "endDateTime", duedateTime
    doc.replaceItemvalue "calendarDateTime", dateTime
    doc.replaceItemvalue "Subject", Subject
    doc.replaceItemvalue "startTime", dateTime
    doc.replaceItemvalue "appointmentType", "3"
    doc.replaceItemvalue "Alarms", "1"
    doc.replaceItemvalue "startDate", dateTime
    doc.replaceItemvalue "endDate", duedateTime
    doc.replaceItemvalue "endTime", duedateTime
    doc.Save True, True
    doc.putInFolder "($Alarms)"
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pdvsaProject financeAuthor Commented:
Sjef:  sorry for the confusion.  I am running the code in Access.  I am transferring from Access into LN.

I think your last post seems to be aligned with this.

I will try it and revert back.   I will be at the computer for awhile now...

thank you
0
pdvsaProject financeAuthor Commented:
Wow!  that worked.

However, when I click on the LN calendar entry, I get 2 error messages:  

1) Error Trying to open document:   Note Item not found
2) Object Variable not set

But after I click OK the note item does open and all seems to be ok.  
Unless you know excatly why I would get this error then I am not interested in finding the solution since it works fine even with the error.

thank you
0
pdvsaProject financeAuthor Commented:
Just a note to any other users that do not have knowledge of this.  

I created a Global Function with the LN code and then modified the OL code using that LN funciton to this:

Private Sub AddLotusNotesTask_Click()

    With Me.[tasks subform].Form
       If AddNotesTask(![StartDate], ![Title], ![DueDate], 8) Then
               MsgBox "The task was added to Lotus Notes"
    End If
   End With
   
End Sub
0
Sjef BosmanGroupware ConsultantCommented:
Good! Confused again, now because of the errors you get. Can you run your code in a debugger, and find out which lines it complains about?
0
pdvsaProject financeAuthor Commented:
Do you mean Debug < Compile, in Access?  

If so , I dont have any errors. I only have the error in LN.  
0
Sjef BosmanGroupware ConsultantCommented:
No, I meant if you debug the code in runtime. It seems possible, see: http://www.techonthenet.com/access/tutorials/vbadebug/debug01.php
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.