2016-08-01 96 views
0

我有一段代码来确保用户在输入“废品代码”时输入“废品量”。当我申请并使用Scrap1的代码时,一切都很好。当我尝试在下一组变量名中应用相同的代码时,我得到一个错误,说我的代码“检测到一个模糊的名字,我检查了我的变量名和代码,直到我的眼睛流血为止。 。有没有人看,我已经错过了一个错误在Access 2013中调试if语句

'check to see that there is a scrap amount if a code has been entered #1. 

Private Sub Form_BeforeUpdate(Cancel As Integer) 
    If Me.ScrapCodes1.Value Then 
    If Me.ScrapAmount1 = 0 Then 
      Cancel = True 
      MsgBox "If Scrap Code is selected, then Scrap Amount must have a value." 
    End If 
    End If 
End Sub 


'check to see that there is a scrap amount if a code has been entered #2. 
Private Sub Form_BeforeUpdate(Cancel As Integer) 
    If Me.ScrapCodes2.Value Then 
    If Me.ScrapAmount2 = 0 Then 
      Cancel = True 
      MsgBox "If Scrap Code is selected, then Scrap Amount must have a value." 
    End If 
    End If 
End Sub 
+2

有您创建了两个'Form_BeforeUpdate'事件您只需要包含在ONE所有代码事件 – dbmitch

+0

谢谢Dbmitch!修正了它!我应该知道的! – Flammie

回答

1

是,组装在一个子:??

Private Sub Form_BeforeUpdate(Cancel As Integer) 

    ' check to see that there is a scrap amount if a code has been entered #1. 
    If Me.ScrapCodes1.Value Then 
     If Me.ScrapAmount1 = 0 Then 
      Cancel = True 
     End If 
    End If 

    ' check to see that there is a scrap amount if a code has been entered #2. 
    If Me.ScrapCodes2.Value Then 
     If Me.ScrapAmount2 = 0 Then 
      Cancel = True 
     End If 
    End If 

    If Cancel = True Then 
     MsgBox "If Scrap Code is selected, then Scrap Amount must have a value." 
    end If 

End Sub 
+0

谢谢!我把它们全部放在before_update中,并且工作正常。 – Flammie