如果字段为空,以下内容将打开一个弹出窗口,如果通过名为 MVR 的 MSVB 用户表单输入时任何字段留空,我希望它弹出。 我有 4 个字段,所以如果不填写,我可以有四个单独的弹出窗口吗?
'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'check for a MVR number
If Trim(Me.txtMVR.Value) = "" Then
Me.txtMVR.SetFocus
MsgBox "Please enter MVR number"
Exit Sub
End If
将
下面的代码添加到您的MSVB
user_form代码模块中(在CommandButton1_Click
事件中,或您拥有的内容中(。
它将遍历User_Form中的所有TextBox
es,如果其中一个留空,它将弹出MsgBox
。
Dim TB As MSForms.TextBox
For Each TB In Me.Controls
If Trim(TB.Value) = "" Then
TB.SetFocus
MsgBox "Please enter a value / number"
Exit Sub
End If
Next TB