如何识别对象是否包含空值

时间:2014-07-13 12:25:01

标签: ms-access access-vba

我对表单(文本框)有一个控件,它引用了一个基础表。我希望有一个命令,在单击时将空值更新为值“未启动”。点击后,我得到一个运行时错误消息424 - 对象必要。

Private Sub Comando50_Click()

  If [txtScope] = ("not started") Then
      [txtScope] = ("proposed")

  ElseIf [txtScope] = ("proposed") Then
      [txtScope] = ("accepted")

  ElseIf [txtScope] Is Null Then
      [txtScope] = ("not started")


  ElseIf [txtScope] = ("accepted") Then
      [txtScope] = ("rejected")


  ElseIf [txtScope] = ("rejected") Then
       [txtScope] = ("on track")

  ElseIf [txtScope] = ("on track") Then
      [txtScope] = ("needs attention")


  ElseIf [txtScope] = ("needs attention") Then
      [txtScope] = ("critical")

  ElseIf [txtScope] = ("critical") Then
      [txtScope] = ("complete")

  ElseIf [txtScope] = ("complete") Then
      [txtScope] = ("not started")

  End If


End Sub

1 个答案:

答案 0 :(得分:0)

假设txtScope是表单上的文本框或字段,那么您应该这样引用它:

Me.txtScope

或者

我!txtScope

您不需要在文本值周围添加括号:

Private Sub Comando50_Click()

  If Me.txtScope = "not started" Then
      Me.txtScope = "proposed"    
  ElseIf Me.txtScope = "proposed" Then
      Me.txtScope = "accepted"
'etc etc
End Sub