+ Reply to Thread
Results 1 to 4 of 4

Thread: Help translating this VB.NET Script into VBA - Retreving Lotus Notes Data

  1. #1
    Forum Contributor
    Join Date
    07-21-2009
    Location
    Sheffield, England
    MS-Off Ver
    Excel 2003
    Posts
    111

    Help translating this VB.NET Script into VBA - Retreving Lotus Notes Data

    Could someone please help me translate this script into something that can be used in Excel VBA. I have a userform setup but the script doesn't like the code in this sub:

    
    Private Sub LookupNOTESAddressBook()
    
            Dim session As Object
            Dim db As Object
            Dim view As Object
            Dim vc As Object
            Dim entry As Object
            Dim items As Object
    
            Dim server As String
            Dim addressbookDB As String
            Dim intCount As Integer
            Dim intFound As Integer
    
            Try
    
                    server = "CN=UK-MAIL-01/OU=SERVERS/O=NOTES"
                    addressbookDB = "names.nsf"
    
                session = CreateObject("Notes.NotesSession")
                db = session.GETDATABASE(server, addressbookDB)
                view = db.GETVIEW("People")
    
                vc = view.GETALLENTRIESBYKEY(strSurname)
    
                entry = vc.GETFIRSTENTRY()
    
                intFound = vc.count
    
                ToolStripStatusLabel1.Text = "Found " & intFound & " matches..."
    
                Application.DoEvents()
    
                If intFound > 0 Then
    
                    intCount = 0
    
                    Do While Not entry Is Nothing
    
                        'Increment count
                        intCount = intCount + 1
    
                        'Pull all columnvalues from entry into ITEMS() array
                        items = entry.COLUMNVALUES
    
                        'Add the value of the 7th item in the ITEMS array to the list box
                        lstResults.Items.Add(items(6))
    
                        'Move to the next entry
                        entry = vc.GETNEXTENTRY(entry)
    
                    Loop
    
                    ToolStripStatusLabel1.Text = "Displaying " & intFound & " results"
    
                Else
    
                    ToolStripStatusLabel1.Text = "No match found"
    
                End If
    
            Catch e As Exception
    
                MsgBox(e.Message, MsgBoxStyle.Information, "NOTES Addressbook Search")
    
            End Try
    
            vc = Nothing
            view = Nothing
            db = Nothing
            session = Nothing
            items = Nothing
    
            txtSurname.Enabled = True
            cmdSearch.Enabled = True
            cmdCancel.Enabled = True
            cmdOK.Enabled = True
    
        End Sub
    Thanks in advance

  2. #2
    Valued Forum Contributor Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds/Sheffield, England
    MS-Off Ver
    Excel 2003
    Posts
    1,031

    Re: Help translating this VB.NET Script into VBA - Retreving Lotus Notes Data

    Give this a whirl, that code looks like something someone wrote in VB6/Excel VBA then converted to .Net so it is fairly easy to convert back

    This is a guess since I don't have lotus notes

    Private Sub LookupNOTESAddressBook()
    
            Dim session As Object
            Dim db As Object
            Dim view As Object
            Dim vc As Object
            Dim entry As Object
            Dim items As Object
    
            Dim server As String
            Dim addressbookDB As String
            Dim intCount As Integer
            Dim intFound As Integer
    
            'Try
    
                    server = "CN=UK-MAIL-01/OU=SERVERS/O=NOTES"
                    addressbookDB = "names.nsf"
    
                session = CreateObject("Notes.NotesSession")
                db = session.GETDATABASE(server, addressbookDB)
                view = db.GETVIEW("People")
    
                vc = view.GETALLENTRIESBYKEY(strSurname)
    
                entry = vc.GETFIRSTENTRY()
    
                intFound = vc.Count
    
                ToolStripStatusLabel1.Text = "Found " & intFound & " matches..."
    
                DoEvents
    
                If intFound > 0 Then
    
                    intCount = 0
    
                    Do While Not entry Is Nothing
    
                        'Increment count
                        intCount = intCount + 1
    
                        'Pull all columnvalues from entry into ITEMS() array
                        items = entry.COLUMNVALUES
    
                        'Add the value of the 7th item in the ITEMS array to the list box
                        lstResults.items.Add (items(6))
    
                        'Move to the next entry
                        entry = vc.GETNEXTENTRY(entry)
    
                    Loop
    
                    ToolStripStatusLabel1.Text = "Displaying " & intFound & " results"
    
                Else
    
                    ToolStripStatusLabel1.Text = "No match found"
    
                End If
    
            'Catch e As Exception
    
               ' MsgBox(e.Message, MsgBoxStyle.Information, "NOTES Addressbook Search")
    
           ' End Try
    
            vc = Nothing
            view = Nothing
            db = Nothing
            session = Nothing
            items = Nothing
    
            txtSurname.Enabled = True
            cmdSearch.Enabled = True
            cmdCancel.Enabled = True
            cmdOK.Enabled = True
    
        End Sub
    Click the * below to say thanks

    Girls sleep with guys who use photoshop, but marry the ones who work with Excel

    Corduroy
    pillows: They're making headlines!

    Did you mean: recursion
    http://www.google.com/search?hl=en&q=recursion

  3. #3
    Forum Contributor
    Join Date
    07-21-2009
    Location
    Sheffield, England
    MS-Off Ver
    Excel 2003
    Posts
    111

    Re: Help translating this VB.NET Script into VBA - Retreving Lotus Notes Data

    Thanks for your reply. I ran the script but I receive an error:

    "Run-time error 91: Object variable or With block variable not set"

    The Debug highlights this line of code:

    session = CreateObject("Notes.NotesSession")

  4. #4
    Valued Forum Contributor Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds/Sheffield, England
    MS-Off Ver
    Excel 2003
    Posts
    1,031

    Re: Help translating this VB.NET Script into VBA - Retreving Lotus Notes Data

    Sorry, I forgot to set the objects, try the below:
    Private Sub LookupNOTESAddressBook()
    
            Dim session As Object
            Dim db As Object
            Dim view As Object
            Dim vc As Object
            Dim entry As Object
            Dim items As Object
    
            Dim server As String
            Dim addressbookDB As String
            Dim intCount As Integer
            Dim intFound As Integer
    
            'Try
    
                    server = "CN=UK-MAIL-01/OU=SERVERS/O=NOTES"
                    addressbookDB = "names.nsf"
    
               Set session = CreateObject("Notes.NotesSession")
               Set db = session.GETDATABASE(server, addressbookDB)
               Set view = db.GETVIEW("People")
    
               Set vc = view.GETALLENTRIESBYKEY(strSurname)
    
               Set entry = vc.GETFIRSTENTRY()
    
                intFound = vc.Count
    
                ToolStripStatusLabel1.Text = "Found " & intFound & " matches..."
    
                DoEvents
    
                If intFound > 0 Then
    
                    intCount = 0
    
                    Do While Not entry Is Nothing
    
                        'Increment count
                        intCount = intCount + 1
    
                        'Pull all columnvalues from entry into ITEMS() array
                      Set items = entry.COLUMNVALUES
    
                        'Add the value of the 7th item in the ITEMS array to the list box
                        lstResults.items.Add (items(6))
    
                        'Move to the next entry
                      Set entry = vc.GETNEXTENTRY(entry)
    
                    Loop
    
                    ToolStripStatusLabel1.Text = "Displaying " & intFound & " results"
    
                Else
    
                    ToolStripStatusLabel1.Text = "No match found"
    
                End If
    
            'Catch e As Exception
    
               ' MsgBox(e.Message, MsgBoxStyle.Information, "NOTES Addressbook Search")
    
           ' End Try
    
            Set vc = Nothing
            Set view = Nothing
            Set db = Nothing
            Set session = Nothing
            Set items = Nothing
    
            txtSurname.Enabled = True
            cmdSearch.Enabled = True
            cmdCancel.Enabled = True
            cmdOK.Enabled = True
    
        End Sub
    Click the * below to say thanks

    Girls sleep with guys who use photoshop, but marry the ones who work with Excel

    Corduroy
    pillows: They're making headlines!

    Did you mean: recursion
    http://www.google.com/search?hl=en&q=recursion

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0