我对我的问题束手无策。我有一张有正数和负数的表。在将两者拆分为单独的表后,我想使用负数的表从使用 vba 的正数的表中删除记录的第一个实例。下面是我的代码:
Public Sub Suppress_Offset()
Dim MYSQL As String
Dim MYSQL2 As String
Dim rst As DAO.Recordset
Dim rst2 As DAO.Recordset
Dim i As Long
Dim db As DAO.Database
MYSQL2 = "select * From Negative where [QUANTITY]<0"
Set db = CurrentDb()
Set rst = db.OpenRecordset(MYSQL2)
If Not rst.EOF Then
rst.MoveFirst
Do Until rst.EOF
MYSQL = ""
MYSQL = MYSQL & "SELECT top 1 *" & vbCrLf
MYSQL = MYSQL & "FROM Positive " & vbCrLf
MYSQL = MYSQL & "Where [Unique ID] = "" & rst![Unique ID]) & "" [ACCOUNT #] = " & rst![ACCOUNT #] & " [MRN]= " & rst![MRN] & vbCrLf
MYSQL = MYSQL & " [PATIENT NAME] = """ & CStr(rst![PATIENT NAME]) & vbCrLf
MYSQL = MYSQL & " [CPT CODE]=""" & CStr(rst![CPT CODE]) & vbCrLf
MYSQL = MYSQL & " [DATE OF SERVICE]=" & rst![DATE OF SERVICE] & vbCrLf
MYSQL = MYSQL & " [ENTRY DATE] = " & rst![ENTRY DATE] & vbCrLf
MYSQL = MYSQL & " [ATTENDING MD] =" & rst![ATTENDING MD] & vbCrLf
MYSQL = MYSQL & " [ATTENDING MD NAME] = """ & CStr(rst![ATTENDING MD NAME]) & vbCrLf
MYSQL = MYSQL & " [DISCHARGE FLOOR] = """ & CStr(rst![DISCHARGE FLOOR]) & vbCrLf
MYSQL = MYSQL & " [DCFL DESC] = """ & CStr(rst![DCFL DESC]) & vbCrLf
MYSQL = MYSQL & " [INOUT CODE] = """ & CStr(rst![INOUT CODE]) & vbCrLf
MYSQL = MYSQL & " [FKEY] = """ & CStr(rst![FKEY]) & vbCrLf
MYSQL = MYSQL & " [DISCHARGE DEPT] = """ & CStr(rst![DISCHARGE DEPT]) & vbCrLf
MYSQL = MYSQL & " [DCDP DESC] = """ & CStr(rst![DCDP DESC]) & vbCrLf
MYSQL = MYSQL & " [FAC/PRO] = """ & CStr(rst![FAC/PRO]) & vbCrLf
MYSQL = MYSQL & " [QUANTITY]>0 and [QUANTITY]>= " & CStr(-rst![QUANTITY])
Debug.Print TypeName(MYSQL), MYSQL
Set rst2 = db.OpenRecordset(MYSQL)
If Not rst2.EOF Then
rst2.Edit
rst2![QUANTITY] = rst2![QUANTITY] + rst![QUANTITY]
rst2.Update
rst.Edit
rst![QUANTITY] = 0
rst.Update
End If
rst2.Close
rst.MoveNext
Loop
End If
rst.Close
End Sub
谁能看到为什么我在以下位置收到运行时错误 13:Set rst2 = db.OpenRecordset(MYSQL)
请帮忙!谢谢
输出 SQL:
String SELECT top 1 *
FROM Positive
Where [Unique ID] = " & rst![Unique ID]) & " [ACCOUNT #] = ########## [MRN]= #######
[PATIENT NAME] = "DOE, BANKSY
[CPT CODE]="#####
[DATE OF SERVICE]=########
[ENTRY DATE] = ########
[ATTENDING MD] =XXXX
[ATTENDING MD NAME] = "BACON, KEVIN
[DISCHARGE FLOOR] = "XXXX
[DCFL DESC] = "RESEARCH/DEVELOPMENT
[INOUT CODE] = "X
[FKEY] = "X-XXXXXXXXXXX
[DISCHARGE DEPT] = "XXXX
[DCDP DESC] = "XXXXXXXX
[FAC/PRO] = "X
[QUANTITY]>0 and [QUANTITY]>= 1
String SELECT top 1 *
FROM Positive
Where [Unique ID] = " & rst![Unique ID]) & " [ACCOUNT #] = ########## [MRN]= #######
[PATIENT NAME] = "DOE, BANKSY
[CPT CODE]="#####
[DATE OF SERVICE]=########
[ENTRY DATE] = ########
[ATTENDING MD] =XXXX
[ATTENDING MD NAME] = "BACON, KEVIN
[DISCHARGE FLOOR] = "XXXX
[DCFL DESC] = "RESEARCH/DEVELOPMENT
[INOUT CODE] = "X
[FKEY] = "X-XXXXXXXXXXX
[DISCHARGE DEPT] = "XXXX
[DCDP DESC] = "XXXXXXXX
[FAC/PRO] = "X
[QUANTITY]>0 and [QUANTITY]>= 1