【问题标题】:Access delete table record vba访问删除表记录vba
【发布时间】: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


    【解决方案1】:

    我设法删除了用户。

    也许有人会从中受益。干杯。 :)

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-30
      • 1970-01-01
      相关资源
      最近更新 更多