Link to home
Create AccountLog in
Avatar of AliciaVee
AliciaVee

asked on

Revise code for Excel to Notes Synchs

Experts,
I need some guidance and "code" suggestions to help with a very basic database.  The Notes (version 6.5) client application will simply track items that a user currently stores on an Excel spreadsheet.  These items are set on each row, with a unique number and data that the user will store include cash amounts (numbers), and other text data in the cells.  The code below is from Lotus Advisor and works great.  I'd like this code enhanced, as indicated in the article:

 "This solution has one minor limitation: It performs a complete replace from Excel to Notes.  If anyone updates the Notes database directly, the next Excel update will wipe those out.  Of course, issues not named in Excel won't be affected."

What the code does is the following:
1. Creates the typical link to the Domino environment via the Notes-Session, NotesDatabase, and NotesView objects.
2. Grabs the contents of cell A9 (the first issue number).
3. Looks in the Notes database to see if that issue already exists; if it does, it grabs
a handle to the document and if it doesn't, it creates a new document.
4. Copies the contents of the row's cells to Notes.
5. Moves to the next cell until there are no more issues.

I've tested the spreadsheet on a development database  and when running the code, I get a popup box saying the following: "A password is required to access ID file" which is strange, because I've never seen this type of message.  I type in my Lotus Notes password, and the box goes away.  

Question 1: Should I assume this is the right password, and if this spreadsheet is given to the user, also assume that he'll need to use 'his' Lotus Notes password?

So, after the password, the data I typed does get pushed to the Lotus Notes datase, and if I create a new line/row of data in the Excel spreadsheet, I get a new document in Notes.  Good so far.  Great.  However, if I edit the document from Notes, and then edit the same or different row in Excel, after the synch, I get a new Notes document of the same one I edited.  So now I have dupe documents, with different data.  Okay, so I can limit the editing of any Notes document, which means only the user in the Excel spreadsheet can edit and add documents -- that will work fine.

Question 2: is the above paragrah the best approach?

I'd like a message to appear, after the synch is successful.  Right now, after I push the button, my mouse pauses for a second or so, and then nothing.  I go in the database and the new data is there.  

Question 3: How can I add a message to the user stating data was syched?

Question 4: I'd like to capture the history of any changes -- in Notes -- made in any of the fields.  
Right now, if the user changes the text on the spreadsheet, it will overwrite the Notes document.  That is fine and we want to dispaly the most recent information, but I'd like to track the previous history.  So, for example:
Field Comments = Customer will send in 5,000 on 10/07
Then, the user changes that to say: Customer will send 3,000 on 10/07
I'd like to capture that hisory in the document somewhere saying something like:
On 6/9/2007 John Smith changes Comments from Customer will send in 5,000 on 10/07 to Customer will send 3,000 on 10/07

Also, I'm hoping that if I set the access level to not allow deletes of Notes documents, except by authorized persons (will not include the user of the spreadsheet) I'm hoping the synch will still work.  I'll be testing that, but thought I should mention it because I don't want the spreadsheet user to delete documents after synchs.  

I know this is a lot -- which is why I'm giving 500 for input/code solutions.  Thanks in advance.

Code:
=====================================================================
Sub SyncWithNotes()

    Dim objNotes As NotesSession
    Dim objDB As NotesDatabase
    Dim objView As NotesView
    Dim objDoc As NotesDocument
    Dim objNotesRichTextItem As NotesRichTextItem
    Dim strNotesServer As String
    Dim strNotesDatabase As String
    Dim strIssues_Number As Integer
    Dim strIssues_Opened As String
    Dim strIssues_Closed As String
    Dim strIssues_Status As String
    Dim strIssues_AssignedTo As String
    Dim strIssues_Narrative As String
   
    Dim objWorksheet As Worksheet
    Dim intRow As Integer
   
    strNotesServer = "NJROS1NDV2001"
    strNotesDatabase = "AliciaV\ExcelIssuesTracking.NSF"
    intRow = 9
   
    Set objNotes = CreateObject("Lotus.NotesSession")
    objNotes.Initialize
    Set objDB = objNotes.GetDatabase(strNotesServer, strNotesDatabase)
    Set objView = objDB.GetView("Issues")
   
    Set objWorksheet = Application.ActiveWindow.ActiveSheet
   
    Do
       
        strIssues_Number = Trim(Str(objWorksheet.Range("A" + Trim(Str(intRow))).Value))
        If Val(strIssues_Number) < 1 Then
            Exit Do
        End If
        strIssues_Opened = objWorksheet.Range("B" + Trim(Str(intRow))).Value
        strIssues_Closed = objWorksheet.Range("C" + Trim(Str(intRow))).Value
        strIssues_Status = objWorksheet.Range("D" + Trim(Str(intRow))).Value
        strIssues_AssignedTo = objWorksheet.Range("E" + Trim(Str(intRow))).Value
        strIssues_Narrative = objWorksheet.Range("F" + Trim(Str(intRow))).Value
       
        Set objDoc = objView.GetDocumentByKey(strIssues_Number)
       
        If objDoc Is Nothing Then
            Set objDoc = objDB.CreateDocument
            Call objDoc.ReplaceItemValue("Form", "Issues")
            Call objDoc.ReplaceItemValue("Issues_Number", strIssues_Number)
            Set objNotesRichTextItem = objDoc.CreateRichTextItem("Issues_Narrative")
        Else
            'This is to delete the current contents
            Call objDoc.RemoveItem("Issues_Narrative")
            Set objNotesRichTextItem = objDoc.CreateRichTextItem("Issues_Narrative")
        End If
       
        Call objDoc.ReplaceItemValue("Issues_Opened", strIssues_Opened)
        Call objDoc.ReplaceItemValue("Issues_Closed", strIssues_Closed)
        Call objDoc.ReplaceItemValue("Issues_Status", strIssues_Status)
        Call objDoc.ReplaceItemValue("Issues_AssignedTo", strIssues_AssignedTo)
        Call objNotesRichTextItem.AppendText(strIssues_Narrative)
        Call objDoc.Save(True, False)
       
        intRow = intRow + 1
       
   
    Loop
   
    Set objWorksheet = Nothing
    Set objDoc = Nothing
    Set objView = Nothing
    Set objDB = Nothing
    Set objNotes = Nothing

End Sub
========================================================
ASKER CERTIFIED SOLUTION
Avatar of marilyng
marilyng

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of SysExpert
I agree with marilyng that it will be a lot more difficult to do in Excel than in Notes Lotus Script.
IN addition, quite a bit of work will need to be done to achieve your goals.

Plenty of good Excel import code available on this site, including some that will handle existing entries and just update them.


I hope this helps !

SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of marilyng
marilyng

Well, I'm not sure I agree with the easier to code in Notes rather than Excel comment from sysExpert.  Both have their advantages and disadvantages.  Really, it depends on what you want to use to drive the logic.
Avatar of AliciaVee

ASKER

Marilyng & SysExpert,

Thanks so much for all of your valuable information (love the detail Marilyng!).  So, over the weekend I searched and thought and rethought and decided to "unmarry" those darn users to excel! Ha! (of course all this "after" I posted this very looooong post).

What I decided to do was use the InViewEdit feature to createa  view that mimics a spreadsheet, and really, the only users that will need to use this is for updates of like 3 columns -- once I get the data into Notes -- maybe more easily than I'm doing now (the initial data is a one time import, then users will need to go to the database to add new items and change/revise existing).  However, there is a second step that will require imports of sales data (using document 2) to link the the current data (document 1).  I'm using an embedded view into the main document of the initial import.

Anyway -- I'm progressing -- its looking good and I agree that I'll have more control in the Notes database -- we'll see how the users like it.  Ugh.

SysExpert -- I'll look into that code for the import and see if its more improved than what I'm using.

Thanks to you both!