【发布时间】:2020-05-12 13:18:41
【问题描述】:
我有一个名为“用户”的表格,格式如下:
Username | Name | Surname | Email | Role | Company |
------------------------------------------------------------------------
jsmith | John | Smith | john.smith@ABC.com | Local admin | ABC |
jdoe | Jane | Doe | jane.doe@DEF.com | User | DEF |
我有一个名为“用户信息”的绑定表单,我可以在其中循环使用下一种格式的用户:
--------------------------------- ---------------------------------
| Username | jsmith | | Username | jdoe |
--------------------------------- ---------------------------------
| Name | John | | Name | Jane |
--------------------------------- ---------------------------------
| Surname | Smith | | Surname | Doe |
--------------------------------- > ---------------------------------
| Email | john.smith@ABC.com | | Email | jane.doe@DEF.com |
--------------------------------- ---------------------------------
| Role | Local admin | | Role | User |
--------------------------------- ---------------------------------
| Company | ABC | | Company | DEF |
--------------------------------- ---------------------------------
接下来是字段名称:
用户名_标签 |用户名
名称标签 |名称
姓氏标签 |姓氏
电子邮件标签 |电子邮件
角色标签 |角色
公司_标签 |公司
我有一个用于退出表单的按钮,一个用于保存数据更改的按钮,我想添加一个用于删除用户的按钮。
你能给我一些建议吗?我将如何去做?
这是“用户信息”表单 vba 代码:
Option Compare Database
Private msaved As Boolean
Private Sub Delete_User_Click()
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
If msaved = False Then
Cancel = True
Me.Undo
Cancel = False
End If
End Sub
Private Sub Exit_Click()
If MsgBox("Are you sure you want to close?", vbInformation + vbYesNo) = vbYes Then
DoCmd.Close acForm, "User Information"
Else
Cancel = True
End If
End Sub
Private Sub Save_Data_Click()
If Me.Dirty Then
If MsgBox("Are you sure you want to save user data?", vbInformation + vbYesNo) = vbYes Then
msaved = True
DoCmd.RunCommand acCmdSaveRecord
MsgBox "User data saved.", vbInformation + vbOKOnly
Else
Exit Sub
End If
msaved = False
DoCmd.Close acForm, "User Information"
Else
MsgBox "You have made no changes.", vbInformation + vbOKOnly
End If
End Sub
Private Sub Form_Current()
msaved = False
txtFucus.SetFocus
For Each ctrl In Me.Controls
If ctrl.Tag = "CHKLEN" Then 'check the tag of the textbox control for the indicator
ctrl.Locked = False
End If
Next ctrl
End Sub
【问题讨论】:
标签: vba ms-access ms-access-forms