设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 2667|回复: 8
打印 上一主题 下一主题

[模块/函数] 怎样自动引用DLL?

[复制链接]
跳转到指定楼层
1#
发表于 2003-6-2 19:42:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
怎样自动引用D:\单位程序\asd.dll 呢?
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅

点击这里给我发消息

2#
发表于 2003-6-2 20:27:00 | 只看该作者
若要试用该示例,请先新建一个类模块,方法是:单击“插入”菜单中的“类模块”,然后将下列代码粘贴到类模块中,并将模块保存为 RefEvents:

' Declare object variable to represent References collection.
Public WithEvents evtReferences As References

' When instance of class is created, initialize evtReferences
' variable.
Private Sub Class_Initialize()
    Set evtReferences = Application.References
End Sub

' When instance is removed, set evtReferences to Nothing.
Private Sub Class_Terminate()
    Set evtReferences = Nothing
End Sub

' Display message when reference is added.
Private Sub evtReferences_ItemAdded(ByVal Reference As _
        Access.Reference)
    MsgBox "Reference to " & Reference.Name & " added."
End Sub

' Display message when reference is removed.
Private Sub evtReferences_ItemRemoved(ByVal Reference As _
        Access.Reference)
    MsgBox "Reference to " & Reference.Name & " removed."
End Sub
以下的 Function 过程可用来添加一个特定的引用。在添加引用时,将执行 RefEvents 类中定义的 ItemAdded 事件过程。

例如,若要将引用设为日历控件,可以传递“C:\Windows\System\Mscal.ocx”字符串(只要该字符串是日历控件在计算机上的正确位置)。

' Create new instance of RefEvents class.
Dim objRefEvents As New RefEvents

' Pass file name and path of type library to this procedure.
Function AddReference(strFileName As String) As Boolean
    Dim ref As Reference

    On Error GoTo Error_AddReference
    ' Create new reference on References object variable.
    Set ref = objRefEvents.evtReferences.AddFromFile(strFileName)
    AddReference = True

Exit_AddReference:
    Exit Function

Error_AddReference:
    MsgBox Err & ": " & Err.Description
    AddReference = False
    Resume Exit_AddReference
End Function
3#
发表于 2003-6-2 22:27:00 | 只看该作者
能否这样说:"归根结底就是AddFromFile方法"?

那么mde是否能行那?
4#
 楼主| 发表于 2003-6-3 01:23:00 | 只看该作者

例如,若要将引用设为日历控件,可以传递“C:\Windows\System\Mscal.ocx”字符串(只要该字符串是日历控件在计算机上的正确位置)。

我想问怎样在打开窗体时自动引用D:\单位程序\asd.dll ,谢谢!
5#
发表于 2003-6-3 01:26:00 | 只看该作者
加载事件过程中写。
6#
发表于 2003-6-3 05:47:00 | 只看该作者
On Error Resume Next
Dim REF As Reference
Dim strfilename As String
strfilename = "c:\program files\common files\system\ado\msado21.tlb" '路径由引用窗体获得
Set REF = Application.references.AddFromFile(strfilename) '必须加APPLICATION
MsgBox REF.Name & "已经被引用完毕" '获得应用名称的途径
7#
发表于 2003-6-3 05:49:00 | 只看该作者
On Error Resume Next
Dim REFE As Reference
Set REFE = Application.references!ADODB '由 添加时的REF.NAME获得
Dim REF As String
REF = REFE.Name
  Application.references.Remove REFE '必须加APPLICATION
   MsgBox REF & "已经被取消引用" '获得应用名称的途径
8#
 楼主| 发表于 2003-6-3 16:19:00 | 只看该作者
谢谢,方法简单一点好
9#
发表于 2003-7-15 05:48:00 | 只看该作者
On Error Resume Next
Dim REFE As Reference
Set REFE = Application.references!ADODB '由 添加时的REF.NAME获得
Dim REF As String
REF = REFE.Name
  Application.references.Remove REFE '必须加APPLICATION
   MsgBox REF & "已经被取消引用" '获得应用名称的途径
是不是在登录窗体的加载事件中写入可以自动引用DLL呢?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-13 09:38 , Processed in 0.106478 second(s), 32 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表