我有一个名为'Users'的表,采用以下格式:
Username | Name | Surname | Email | Role | Company |
------------------------------------------------------------------------
jsmith | John | Smith | [email protected] | Local admin | ABC |
jdoe | Jane | Doe | [email protected] | User | DEF |
我有一个名为“用户信息”的装订表格,可以在其中以下一种格式循环用户:
--------------------------------- ---------------------------------
| Username | jsmith | | Username | jdoe |
--------------------------------- ---------------------------------
| Name | John | | Name | Jane |
--------------------------------- ---------------------------------
| Surname | Smith | | Surname | Doe |
--------------------------------- > ---------------------------------
| Email | [email protected] | | Email | [email protected] |
--------------------------------- ---------------------------------
| Role | Local admin | | Role | User |
--------------------------------- ---------------------------------
| Company | ABC | | Company | DEF |
--------------------------------- ---------------------------------
字段名称是下一个:
Username_Label |用户名
Name_Label |名称
Surname_Label |姓
Email_Label |电子邮件
角色标签|角色
Company_Label |公司
我有一个用于退出表单的按钮,一个用于保存数据更改的按钮,并且我想添加用于删除用户的按钮。
您能否给我一些建议,以解决该问题?
这是'用户信息'形式的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
我设法删除了用户。
也许有人会从中受益。干杯。 :)
Private Sub Delete_User_Click()
If MsgBox("Are you sure you want to delete user?", vbInformation + vbYesNo) = vbYes Then
strSQL = "DELETE * FROM [Users]" & "WHERE [Username] = '" & Me.Username & "'"
CurrentDb.Execute strSQL, dbFailOnError
MsgBox "User deleted.", vbInformation + vbOKOnly"
End If
End Sub