我的应用程序是为VB.NET中的扫描MS Access数据库构建的.
当Access应用程序分发给最终用户时,它们可能具有不同版本的COM组件.是否可以通过编程方式添加/删除引用以解决由于版本不同而导致的损坏引用?
请分享我的代码或链接以供参考.
以下是一些示例代码:
从文件创建引用
Sub AddWS() 'Create a reference to Windows Script Host, ' 'where you will find FileSystemObject ' 'Reference name: "IWshRuntimeLibrary" ' 'Reference Name in references list: "Windows Script Host Object Model" ' ReferenceFromFile "C:\WINDOWS\System32\wshom.ocx" End Sub Function ReferenceFromFile(strFileName As String) As Boolean Dim ref As Reference On Error GoTo Error_ReferenceFromFile References.AddFromFile (strFileName) ReferenceFromFile = True Exit_ReferenceFromFile: Exit Function Error_ReferenceFromFile: ReferenceFromFile = False Resume Exit_ReferenceFromFile End Function
删除参考
Sub DeleteRef(RefName) Dim ref As Reference 'You need a reference to remove ' Set ref = References(RefName) References.Remove ref End Sub You can use the references collection to find if a reference exists.
参考文献存在
Function RefExists(RefName) Dim ref As Object RefExists = False For Each ref In References If ref.Name = RefName Then RefExists = True End If Next End Function
来自:http://wiki.lessthandot.com/index.php/Add,_Remove,_Check_References
您可能还希望阅读 http://www.mvps.org/access/modules/mdl0022.htm