vba - 如何设置引用库数据库的变量
问题描述
目前,我正在为我的所有 Access 应用程序开发一个库数据库,其中包含通用代码和表单。它进展顺利,但我唯一无法发现的是如何设置引用引用的变量。库名称由一个常量设置,并在启动时检查该文件是否存在于应用文件夹中,以及该文件是否等于存储在引用中的路径。
但是,我想用一个短变量“dbl”来引用库,因为我不想每次都使用库名。这个名字也可能会改变。如何设置变量来执行此操作?我试过 Set dbl = Application.References(APP_LIB)
了,这被认为是有效的,但我不能用这个变量调用任何例程或表单。
谢谢!
艺术。
Public Function CkLib()
'Needs to stay in the App Module!
Dim ref As Reference
Dim strLib As String
On Error GoTo Err_Proc
For Each ref In Application.References
If ref.Name = APP_LIB Then
strLib = CurrentProject.Path & "\" & ref.Name & "." & APP_LIB_TYPE
If Dir(strLib, vbNormal) = "" Then 'File does not exist
MsgBox "The app library " & APP_LIB & " is missing. Please reinstall the app or ask for support!", vbCritical + vbOKOnly, APP_NAME & " App Error"
DoCmd.Quit acQuitSaveNone
Else
If ref.FullPath <> strLib Then 'Path needs to be updated
References.Remove ref
References.AddFromFile strLib
End If
Exit For
End If
End If
Next ref
If Nz(strLib, "") = "" Then
'Try to add ref
If Dir(CurrentProject.Path & "\" & APP_LIB & "." & APP_LIB_TYPE, vbNormal) <> "" Then
References.AddFromFile strLib
Else
MsgBox "Missing reference to app library " & APP_LIB & "! Please reinstall the app or ask for support!", vbCritical + vbOKOnly, APP_NAME & " App Error"
DoCmd.Quit acQuitSaveNone
End If
End If
Set dbl = Application.References(APP_LIB)
Exit_Proc:
Exit Function
Err_Proc:
Select Case Err.number
Case Else
MsgBox "Error: " & Trim(Str(Err.number)) & vbCrLf & _
"Desc: " & Err.description & vbCrLf & vbCrLf & _
"Module: Mod_Generic" & vbCrLf & _
"Function: CkLib", _
vbCritical, "Error!"
End Select
Resume Exit_Proc
End Function
解决方案
推荐阅读
- c# - 数组字符串分组到特定集合
- android - 如何更改标签页图标颜色?
- python - 一种 Pythonic 方法来更改应从调用 cancel() 的位置取消异步任务的方式
- angular - 错误:“文本”类型上不存在属性“innerHTML”。角度 2+ 。打印数据表图像未打印时
- c# - 控制台是 C# 中的一个类,但作为一个对象工作?
- html - 如何在导航菜单中添加图片?
- .net - 微软bot框架中聊天机器人的AD单点登录机制
- python - 使用属性类型创建描述符时出现递归错误
- python - 如何更新 tkinter 消息
- java - 分配 Set 中的所有值
到地图 有溪流