我有一个按钮,它使用两个单独的查询从两个表中提取数据并插入到另一个表中:
Dim lngID As Long
Dim lngIDCallout As Long
Dim strSQL1 As String
lngID = CalloutAttendance_MultiSelect.Value
lngIDCallout = Forms![Callouts].[CalloutID].Value
strSQL1 = "INSERT INTO Members_Callouts(MemberID) SELECT MemberID FROM Members WHERE MemberID=" & lngID
strSQL2 = "INSERT INTO Members_Callouts(CalloutID) SELECT CalloutID FROM Callouts WHERE CalloutID=" & lngIDCallout
CurrentDb.Execute strSQL1
CurrentDb.Execute strSQL2
CalloutAttendance_MultiSelect.Requery
虽然它几乎做了我想要它做的事情,但它将这两个值作为两个单独的新记录插入,而我希望它将它插入一个新记录。我已经尝试过了,但是我遇到了语法错误,或者在下面的情况下,我收到了 3067 运行时错误“查询输入必须包含至少一个表或查询”
strSQL1 = "INSERT INTO Members_Callouts(MemberID, CalloutID) SELECT
(SELECT MemberID FROM Members WHERE MemberID=" & lngID & "),
(SELECT CalloutID FROM Callouts WHERE CalloutID=" & lngIDCallout & ")"
有人知道我可能会出错吗?
谢谢 :-)