使用链接表在Recordset上超时

时间:2012-03-05 15:36:35

标签: vba

Dim rt As DAO.Recordset

strSQL = "SELECT DISTINCT A.OBJ FROM " 
strSQL = strSQL & "(SELECT VARBL AS OBJ FROM AGR_1252 WHERE AGR_NAME = '" _
    & AGR & "') A LEFT JOIN " 
strSQL = strSQL _
    & "(SELECT DISTINCT CONF_USOBT_C_ORG.ORG_OBJECT AS OBJ FROM Role_Content, CONF_USOBT_C_ORG " 
strSQL = strSQL & "WHERE Role_Content.AGR_NAME = '" _
    & AGR & "' AND Role_Content.TCode = [CONF_USOBT_C_ORG].[Name] AND Role_Content.TCode <> '" & tc & "') B " 
strSQL = strSQL & "ON A.OBJ = B.OBJ WHERE B.OBJ Is Null"

Set rt = CurrentDb.OpenRecordset(strSQL)

  Do While Not rt.EOF

      DoCmd.RunSQL "DELETE FROM AGR_1252 WHERE AGR_NAME = '" & AGR & "' AND VARBL = '" & rt("OBJ") & "'" ', False

rt.MoveNext

    Loop

rt.Close
Set rt = Nothing

我有上面的代码。我不知道为什么,但它在while循环中给了我一个超时错误。我不知道是不是因为Recordset,但是在他做了第一次删除之后桌子就阻塞了。

还有另一种方法可以在不使用RecordSet的情况下选择记录吗?

提前致谢。

1 个答案:

答案 0 :(得分:0)

我认为您可能正在寻找以下内容:

DELETE FROM AGR_1252 
WHERE AGR_NAME = Agr
AND Varbl Not In (
  SELECT c.ORG_OBJECT 
  FROM Role_Content r 
  INNER JOIN CONF_USOBT_C_ORG c 
  ON r.TCode =c.[Name]
  WHERE r.AGR_NAME Is Null)