2014-11-25 125 views
0
Dim rst1 As DAO.Recordset 
Dim rst2 As DAO.Recordset 

Set rst1 = CurrentDb.OpenRecordset("Table1", 2) 
Set rst2 = CurrentDb.OpenRecordset("Table2", 2) 

Dim strName As String 

If Not (rst1.EOF And rst1.BOF) Then 
    rst1.MoveFirst 
    Do Until rst1.EOF 
     rst1.Edit 

     strName = rst1![Name] 
     rst2.FindFirst ("[Name] = '" & strName & "'") 

     If rst2.NoMatch Then 
      If rst1![Accepted] Is Not Null Then 'here is the line causing error 
       ... 'more code going on 

因此,上面是我的代码的摘录。我尽可能简化了它,而不改变上下文。情况如下:VBA中的运行时错误424访问

我有两个表,并希望检查表1中的人是否已经存在于表2中。如果是这种情况,那就忽略它。如果不是,那么我想检查Table1中的另一个条件(如果DateTime字段[Accepted]不是NULL),并且如果它满足继续处理该人员的数据。

然而,即使我能够得到妥善rst1![Name],当我进入内if我得到424运行时错误:所需的对象

任何想法如何克服这一点?

回答

0

第二If语句来应显示

If Not IsNull(rst1![Accepted]) Then 

Is - 运算符用于比较对象引用,从而该错误消息。

+0

工程就像一个魅力,非常感谢! – pkrysiak 2014-11-25 11:51:17

+0

啊,我明白了。谢谢。 – paulroho 2014-11-25 11:55:47