如何通过 VBA 连接到 Lotus Notes 数据库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2150586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I connect to a Lotus Notes DB through VBA?
提问by Alymon
I'm trying to connect to a Lotus Notes database via VBA in Microsoft Access 2003. The code I have is as follows:
我正在尝试通过 Microsoft Access 2003 中的 VBA 连接到 Lotus Notes 数据库。我的代码如下:
Set nSession = CreateObject("Notes.NotesSession")
Set nSession = CreateObject("Notes.NotesSession")
Set nDatabase = nSession.GetDatabase("CN=MT_N01/O=Org Name", "LossPrevention\BrchPrVI.nsf", False)
Set nDatabase = nSession.GetDatabase("CN=MT_N01/O=Org Name", "LossPrevention\BrchPrVI.nsf", False)
I've tried variations for the server name, but nothing seems to work. In Lotus Notes it appears as "Server: MT_N01/Org Name". I've tried just "MT_N01" and "MT_N01/Org Name", but the NotesDatabase variable keeps ending up empty.
我尝试了服务器名称的变体,但似乎没有任何效果。在 Lotus Notes 中,它显示为“服务器:MT_N01/组织名称”。我只试过“MT_N01”和“MT_N01/Org Name”,但 NotesDatabase 变量一直为空。
Any tips?
有小费吗?
回答by SaguiItay
I might be wrong here, but I think you should call the Initialize() method of the session prior to using it.
我在这里可能错了,但我认为您应该在使用会话之前调用它的 Initialize() 方法。
Take a look at the samples here: http://www.ibm.com/developerworks/lotus/library/domino-msnet/index.html
看看这里的示例:http: //www.ibm.com/developerworks/lotus/library/domino-msnet/index.html
回答by Anders Lindahl
I think that behaviour is normal; VBA knows nDatabase
is a variant/object, but does not know anything about its contents. At least that is what I get when I try your code in Excel 2003.
我认为这种行为是正常的;VBA 知道nDatabase
是一个变体/对象,但对其内容一无所知。至少这是我在 Excel 2003 中尝试您的代码时得到的结果。
Try to return something from the database object, for example nDatabase.ReplicaID
should return the database identity string. If the databas is not properly loaded, you will get an error.
尝试从数据库对象返回一些东西,例如nDatabase.ReplicaID
应该返回数据库标识字符串。如果数据库未正确加载,您将收到错误消息。
Many good links are posted in response to the ".NET and Lotus Notes Interop."question.
为响应“.NET 和 Lotus Notes Interop”,发布了许多好的链接。题。
回答by Richard Schwartz
Unless you also need to us the NotesUIWorkspace class and its child classes to manipulate the Notes client user interface, you should be using the "Lotus.NotesSession" class instead of the "Notes.NotesSession" class. And as per the answer from @Sagultay, you should be calling nSession.Intialize()
.
除非您还需要使用 NotesUIWorkspace 类及其子类来操作 Notes 客户端用户界面,否则您应该使用“Lotus.NotesSession”类而不是“Notes.NotesSession”类。根据@Sagultay 的回答,您应该致电nSession.Intialize()
.