T-R*_*Rex 3 ms-access vba access-vba
我有这个简单的访问表单,当你填写表单并忘记填写业务单位字段时,会弹出一个msgBox告诉你这样,并将setFocus设置为那个非常组合框.如果它不为null,我想调用下一个功能.这段代码的第一部分可以工作,但是当它不是Null时它不会继续.
Private Sub Image_AddNon_RPS_Button_Click()
If IsNull(Me.BU_Selected_Add) Then
MsgBox "Please Select a Business Unit!", vbOKOnly
Exit Sub
End If
Me.Combo_BU_Selector.SetFocus
Exit Sub
If Not IsNull(Me.BU_Selected_Add) Then
Call Add_RPS_LINE
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
有人看到我完全在左外野的地方吗?
你有一个额外的Exit Sub(第一个之后的那个MsgBox)阻止你的代码做你想要的.此外,你的第一个End If是在错误的位置.
尝试这样的事情:
Private Sub Image_AddNon_RPS_Button_Click()
If IsNull(Me.BU_Selected_Add) Then ' No business unit
MsgBox "Please Select a Business Unit!", vbOKOnly ' Tell user
Me.Combo_BU_Selector.SetFocus ' Focus the control
Exit Sub ' Exit the method
End If ' End the IsNull test
Call Add_RPS_LINE ' You only get here if the above doesn't execute
End Sub
Run Code Online (Sandbox Code Playgroud)
它可以帮助你学会正确缩进代码来匹配If和End If可视化,所以你可以看到他们排队(匹配),并在那里他们没有.:-)
| 归档时间: |
|
| 查看次数: |
82666 次 |
| 最近记录: |