我有一个小问题.....
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) " _
上面的错误给了我
当我在“位置”部分中替换时 [Date 2]与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
我有一些代码,现在我故意告诉访问要忽略,直到找到解决方案为止。...我计划将where或part添加到where语句,以便它通过Date()或[Date]运行查询2]
有什么想法吗?
答案 0 :(得分:0)
在日期之前和之后尝试##
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) " _