vba - 参数太少,预期为 1
问题描述
我有一个小问题......
DDA3 = "SELECT DDAs.[QR Code], DDAs.[Drug Name and Strength],DDAs.[Dispensing Date], DDAs.[Amount Prescribed], DDAs.[Prescription Date], DDAs.[Record Number], DDAs.[NOT DISPENSED] " _
& "FROM DDAs " _
& "WHERE ([DDAs].[QR Code] = [QR Code] AND [DDAs].[Dispensing Date] = [Date 2] AND [DDAs].[NOT DISPENSED] = No) " _
以上给了我错误
当我在 WHERE 部分 [Date 2] 中替换为 Date() (使用今天的日期而不是控件中的日期)时,它可以正常工作....
我需要使用 [Date 2] 我尝试重命名控件不断出现相同的错误,尝试删除 [QR Code] 以声明只有一个控件仍然不起作用...
(完整代码如下:
'On Error Resume Next
[Date 2] = Date
Dim rs As DAO.Recordset
Dim strOutput As String
Dim i As Integer
'Dim Date2 As Date
DDA3 = "SELECT DDAs.[QR Code], DDAs.[Drug Name and Strength],DDAs.[Dispensing Date], DDAs.[Amount Prescribed], DDAs.[Prescription Date], DDAs.[Record Number], DDAs.[NOT DISPENSED] " _
& "FROM DDAs " _
& "WHERE ([DDAs].[QR Code] = [QR Code] AND [DDAs].[Dispensing Date] = [Date 2] AND [DDAs].[NOT DISPENSED] = No) " _
'OR ([DDAs].[QR Code]=[QR Code] AND [DDAs].[Dispensing Date]= [DateMod] AND [DDAs].[NOT DISPENSED]= No) " _
Set rs = CurrentDb.OpenRecordset(DDA3)
With rs
'test for empty recordset
If Not .EOF And Not .BOF Then
.MoveLast
.MoveFirst
Dim cdg As String
cdg = UCase([Forms]![POYC].[txtEnterState6])
For i = 0 To (.RecordCount - 1)
'test for last record
If i = (.RecordCount - 1) Then
'last record
strOutput = strOutput + ![Amount Prescribed] + " " + ![Drug Name and Strength]
Else
'all other records
strOutput = strOutput + ![Amount Prescribed] + " " + ![Drug Name and Strength] + vbCrLf
End If
.MoveNext
Next
End If
.Close
End With
'execute messagebox
MsgBox "The following DDA prescriptions for " & [cdg] & " have been dispensed:" & vbCrLf & vbCrLf & UCase([strOutput]), vbInformation + vbOKOnly, "DDA records!"
Set rs = Nothing
我有一些代码,我故意告诉访问暂时忽略,直到我找到解决方案....我计划将 or 部分添加到 where 语句中,以便它通过 Date() 或 [Date 2] 运行查询
有任何想法吗?
解决方案
尝试在日期之前和之后使用 #
DDA3 = "SELECT DDAs.[QR Code], DDAs.[Drug Name and Strength],DDAs.[Dispensing Date], DDAs.[Amount Prescribed], DDAs.[Prescription Date], DDAs.[Record Number], DDAs.[NOT DISPENSED] " _
& "FROM DDAs " _
& "WHERE ([DDAs].[QR Code] = [QR Code] AND [DDAs].[Dispensing Date] = #" & [Date 2] & "# AND [DDAs].[NOT DISPENSED] = No) " _
推荐阅读
- c++ - 推回功能的容量问题
- user-interface - 是否可以在没有对象大小的情况下计算每度视角的点数?
- reactjs - 使用 ReactRouter nas PHP 托管进行反应
- performance - Spring JPA 在 postgres 数据库中插入数据需要太多时间和内存
- python - 使用用户的输入在 excel 文件中搜索特定行(python)
- javascript - React Native中VirtualzedList更新慢时返回的对象含义
- php - 以逗号分隔的字符串拆分并在 MySQL 和 PHP 中显示
- python - 具有多个迭代器的 Python 多处理部分池
- python - 限制 Windows 中的 python 脚本 RAM 使用
- ruby-on-rails - 更好的替代尝试方法