forms - MsAccess 表单 - 最初为空记录,但需要在数据输入开始后强制填写
问题描述
我有 MsAccess 表格:
ClientName, ID fields - records filled with the information
Gender, Race, PrimaryLanguage fields (combo box type) are empty records
用户将使用这些信息填写 Gender、Race 和 PrimaryLanguage、PrimaryDisability 字段。我的目标是 - 在用户移动到下一条记录之前,我希望他在这些字段(性别/种族)填满其内容之前无法继续。
问题是 - Gender / Race / PrimaryLanguage,现有客户的PrimaryDisability必须保持空白,但同时 - 当用户开始填写时,需要强制填写。
只有在我添加新记录的情况下,它才会以这种方式工作。(我有需要的性别/种族字段) - 但不适用于现有记录。
PS - 下面提供的答案很棒,但我只为 2 个字段工作了 3 个或更多字段呢?
我想将事件过程添加到表单中的每个按钮,而不是整个表单。代码应该是这样的:
Private Sub Gender_BeforeUpdate(Cancel As Integer)
If Nz(Me.Gender, "") = "" And (Nz(Me.Race, "") <> ""
Or (Nz(Me. PrimaryLanguage, "") <> ""
Or (Nz(Me. PrimaryDisability, "") <> "")
Then
MsgBox "Select Gender", vbInformation
Cancel = True
End If
End Sub
但它说的是语法错误
请帮忙!
解决方案
BeforeUpdate
在移动到另一条记录之前使用事件取消记录的更新
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Nz(Me.ClientName, "") <> "" And Nz(Me.Gender, "") = "" And Nz(Me.Race, "") = "" And Nz(Me.PrimaryLanguage, "") = "" And Nz(Me.PrimaryDisability, "") = "" Then
Exit Sub
End If
If Nz(Me.Gender, "") = "" Then
MsgBox "Select Gender", vbInformation
Cancel = True
Exit Sub
End If
If Nz(Me.Race, "") = "" Then
MsgBox "Select Race", vbInformation
Cancel = True
Exit Sub
End If
If Nz(Me.PrimaryLanguage, "") = "" Then
MsgBox "Enter PrimaryLanguage", vbInformation
Cancel = True
Exit Sub
End If
If Nz(Me.PrimaryDisability, "") = "" Then
MsgBox "Enter PrimaryDisability ", vbInformation
Cancel = True
Exit Sub
End If
End Sub
推荐阅读
- entity - Sulu:如何查询自定义实体类型?
- ios - iOS Swift如何从json响应中获取任何键的值
- python - 在 jupyter notebook 中使用 tensorflow 加载数据时出现警告
- networking - 带宽对 lorawan 范围有什么影响?
- r - 如何在 R 中实现拒绝抽样?
- excel - 当某些单元格是VBA中的某个数字时如何不打印工作表(while循环)
- python - Heroku Procfile 与多个工人
- rust - 使用 Rust/git2 将远程拉入本地分支
- docker - 通过 docker-compose 和环境变量将单个文件复制到容器中
- reactjs - ReactJS 中的映射方法