vba - 访问 DLookUp 返回 Null
问题描述
我一直在寻找,似乎无法找到答案。我遵循了在网上找到的其他示例代码的示例,但没有任何效果。我试图从我的数据库查询中的特定单元格中获取一串评论到同一数据库中表单的文本框中。我收到错误 13 不匹配错误和 96?空错误。下面是我的代码:
Private Sub Text757_Click()
Dim Remarks757 As String
If IsNull(DLookup("Remarks", "QueryDataPaveAll", "[YrRated] = Forms![FormDataEntryPave]![TextYrRated]" And "[RdSecNo] = Forms![FormDataEntryPave]![TextRdSecNo]")) Then
MsgBox "No Record Found"
Else
Remarks757 = DLookup("Remarks", "QueryDataPaveAll", "[YrRated] = Forms![FormDataEntryPave]![TextYrRated]" And "[RdSecNo] = Forms![FormDataEntryPave]![TextRdSecNo]")
Me.Text757 = Remarks757
End If
End Sub
解决方案
问题是Null
from 找不到任何东西时的返回值不能存储为 a String
,因此您必须声明Remarks757
为 aVariant
Private Sub Text757_Click()
Dim Remarks757 As Variant
Remarks757 = DLookup("Remarks", "QueryDataPaveAll", "[YrRated] = Forms![FormDataEntryPave]![TextYrRated]" And "[RdSecNo] = Forms![FormDataEntryPave]![TextRdSecNo]")
If IsNull(Remarks757) Then
MsgBox "No Record Found"
Else
Me.Text757 = Remarks757
End If
End Sub
推荐阅读
- amazon-web-services - 我需要使用秘密管理器秘密为 ec2 实例创建用户名和密码
- android - 如果从最近清除应用程序,BroadcastReceiver 在 2 或 3 分钟后不工作
- google-bigquery - 如何识别分区内的日期差异?
- time-series - 处理每日温度时间序列插值过程中的缺失数据
- firefox - 用户代理中的 gzip(gfe) 是什么
- jquery - jQuery 和 iOS 设备
- swift - 在集合视图中使用可重用单元格的问题
- java - environment.getProperty("property") 是否产生与 @Value("property") 相同的值
- javascript - 分配给不同容器时预加载的图像重新加载?
- python - 如何使用 cx_Freeze 将目录添加到系统路径环境变量?