Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA to Open Specific Notes Document (NOT an email document)

Status
Not open for further replies.

pscribby

Programmer
Aug 20, 2009
5
US
I am trying to write a VBA module for use inside an MS Access database. Inside the Access dB, I have a claim number. I need to set up a button on my form in Access which, when clicked opens the Claims Database, which is a Lotus Notes Database. I do not need to transfer any data in either direction, I just want to open the Notes database in the client of Lotus Notes, and show the form view for the record (document in Notes terminology) that matches my claim number. I do not know Notes at all. I have managed to enable the Notes objects/classes in Visual Basic, but don't know how to correctly use them. I have the server path, database file name, name of the form inside the Notes dB, and the name of the field on the Notes form (which I need to match to my variable)...
So far, I can only successfully open the Notes database using a shell command. I have a test code module where I have been able to successfully (I think) declare the needed variables, set session, set db, but db.open gives me a "type mismatch" error. Below is the code so far (which isn't working... and I have not added the details to specify the field and search variable yet):

Private Sub test2()

Dim db As Object
Dim dbname As String
Dim dbpath As String
Dim session As Object
Dim view As Object

Set session = CreateObject("Notes.NotesSession")

dbname = "<mydatabase.nsf>"
dbpath = "<myserverpath/>"
Set db = session.GetDatabase(dbpath, dbname)

Set view = db.GetView("<myformname>")

db.Open


End Sub
 
I cannot be of much help because I do not have Notes to play with (and do not know much about it) but I think a Google for;

createobject("notes.notesuiworkspace")

may be of help. Most examples are for email from vb code (my main interest) but it seems notesuiworkspace needs to be used to get Notes to display stuff on-screen.

A Google for 'Domino' may give you an object model.

forum9 may be worth a try.
 
Thanks HughLerwill!

I have 2 different paths I experimenting with. One of them includes the notes.notesuiworkspace method that you mentioned. Below is the code so far:

Private Sub test2()

Dim db As Object
Dim dbname As String
Dim dbpath As String
Dim dbfull As String
Dim session As Object
Dim view As Object
Dim doc As Object
Dim docname As String

docname = "<a known good doc number>"

Set session = CreateObject("Notes.NotesSession")

Set uiworkspace = CreateObject("Notes.Notesuiworkspace")

dbname = "<mydbname>"
dbpath = "<mypathname>"
Set db = session.GetDatabase(dbpath, dbname)

Set view = db.GetView("fm_ClaimCase")

End Sub

This code does not throw any errors on debug, and when I run it, no errors appear - but nothing seems to happen either (ie: the notes ui session does not open). I have another approach in which I can successfully open the notes ui workspace using a shell command, but where I get stuck there is that I can't figure out how to specify the view/form and the document I want opened on said view/form... I've Google'd this dozens and dozens of times every which way I can think of... all I keep getting are ways to generate emails from/inside of Notes... nowhere am I finding anything on opening a non-email Notes database... I will also look in the other forum you mentioned to see if somebody there maybe has an idea...
All ideas are appreciated! Thanks!
 
Checkout use of Notesuiworkspace in this link (wiglaer's) code. I suspect it is the

ws.EDITDOCUMENT True, MailDoc

which is getting the email onscreen in a state of edit, may be the data you require can be made visible in a similar manner. More on EditDocument at
Your psuedo code appears to make no use of the uiworkspace object after it has been created.
 
HughLerwill, you're my hero!
While the link for edit document was not what I was looking for, the site contained the class objects for NotesUIWorkspace... in there I found the proper syntax to directly open the Notes database on a view and on a specific record... the code below WORKS!!!

Public Function openLegalClaim(legalclaim As String)


Dim dbname As String
Dim dbpath As String
Dim docname As String
Dim notesuiworkspace As Object

docname = legalclaim

Set notesuiworkspace = CreateObject("Notes.Notesuiworkspace")

dbname = "<dbname>"
dbpath = "<dbserverpath>"

Call notesuiworkspace.OpenDatabase(dbpath, dbname, "<viewname>", docname, False, False)



End Function

The trick is that the first column of the view must contain the values you want to search on, and they must be sorted... this code opens the view and jumps down the sorted list to the value you pass in... (I need our Notes dB administrator to create a custom view for me that's tailored to my specific needs now, but that's already underway :) ). Now, it seems the only challenge remaining is that when my Notes database opens, it is NOT the active window... usually UNDER my MSACCESS dB from which I am running my VBA code... know of a simple way to switch the active window to a specific application window that's not on top??

Thanks again for the advice - no way I would have gotten this far without the link to the notesuiworkspace class!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top