我正在尝试在我的未绑定表单上使用脏选项。我该怎么做呢?以下是表单的所有代码。在访问 2010 [关闭]

Posted

技术标签:

【中文标题】我正在尝试在我的未绑定表单上使用脏选项。我该怎么做呢?以下是表单的所有代码。在访问 2010 [关闭]【英文标题】:i am trying to use the dirty option on my unbound form. how do i do this? below is all the code for the form. in access 2010 [closed] 【发布时间】:2014-08-26 12:28:28 【问题描述】:

我正在尝试使用脏选项,但不知道从哪里开始,因为它是一个未绑定的表单,我该如何正确编码? 如果可能,我想在关闭事件中使用 form.dirty。

Private Sub cmd_saverecord_Click()

    Call saverecord

End Sub


Private Sub Form_Load()

        Dim sql As String, db As DAO.Database, rs As Recordset
        Set db = CurrentDb
        sql = "SELECT tbl_vr.*, tbl_customer.customer_name, tbl_customer.customer_number, tbl_customer.customer_d_number, tbl_customer.customer_email " _
            & "FROM tbl_vr INNER JOIN tbl_customer ON tbl_vr.customer_id = tbl_customer.customer_id " _
            & "WHERE tbl_vr.vr_id=" & get_current_vr_id()
        Set rs = db.OpenRecordset(sql, dbOpenDynaset)
        With rs
            txt_vr_id = .Fields("vr_id")
            txt_vr_reference = .Fields("vr_reference")
            txt_external_reference = .Fields("vr_external_reference")
            txt_vr_project = .Fields("vr_project")
            cbo_part_master_id = .Fields("part_master_id")
            cbo_part_master_revised_id = .Fields("part_master_revised_id")
            txt_vr_creation_date = .Fields("vr_creation_date")
            txt_vr_anticipated_dispatch = .Fields("vr_anticipated_dispatch")
            txt_vr_quote_to_customer = .Fields("vr_quote_to_customer")
            txt_vr_quote_acceptance = .Fields("vr_quote_acceptance")
            txt_vr_quote_rejection = .Fields("vr_quote_rejection")
            txt_vr_received_at_mbda = .Fields("vr_received_at_mbda")
            txt_vr_sent_to_repairer = .Fields("vr_sent_to_repairer")
            txt_vr_received_from_repairer = .Fields("vr_received_from_repairer")
            txt_vr_predicted_return_date = .Fields("vr_predicted_return_date")
            txt_vr_actual_dispatch_date = .Fields("vr_actual_dispatch_date")
            txt_vr_received_by_customer = .Fields("vr_received_by_customer")
            txt_vr_serial_no = .Fields("vr_serial_no")
            txt_customer_name = .Fields("customer_name")
            txt_user_id = .Fields("user_id")
            txt_customer_email = .Fields("customer_email")
            txt_customer_number = .Fields("customer_number")
            txt_customer_number_d = .Fields("customer_d_number")
            cbo_part_master_id_AfterUpdate
            cbo_part_master_revised_id_AfterUpdate
        End With
        Me.cbo_dates.RowSource = ""
        sql = "SELECT tbl_roles.* " _
            & "FROM tbl_roles INNER JOIN tbl_user ON tbl_roles.[Role ID] = tbl_user.role_id " _
            & "WHERE tbl_user.user_id =" & get_user_id()
        Set rs = db.OpenRecordset(sql, dbOpenDynaset)
        With rs
            If .Fields("role_creation_date") = True Then 

        Me.cbo_dates.AddItem "role_creation_date" & "; " & "Creation Date"
                If .Fields("role_anticipated_dispatch") = True Then Me.cbo_dates.AddItem "role_anticipated_dispatch" & "; " & "Dispatch to MBDA"
                If .Fields("role_quote_to_customer") = True Then Me.cbo_dates.AddItem "role_quote_to_customer" & "; " & "Quote to Customer"
                If .Fields("role_quote_acceptance") = True Then Me.cbo_dates.AddItem "role_quote_acceptance" & "; " & "Quote Acceptance"
                If .Fields("role_quote_rejection") = True Then Me.cbo_dates.AddItem "role_quote_rejection" & "; " & "Quote Rejected"
                If .Fields("role_received_at_mbda") = True Then Me.cbo_dates.AddItem "role_received_at_mbda" & "; " & "Received at MBDA"
                If .Fields("role_sent_to_repairer") = True Then Me.cbo_dates.AddItem "sent_to_repaierer" & "; " & "Sent to Repairer"
                If .Fields("role_received_from_repairer") = True Then Me.cbo_dates.AddItem "received_from_repaierer" & "; " & "Received from Repairer"
                If .Fields("role_predicted_return_date") = True Then Me.cbo_dates.AddItem "role_predicted_return_date" & "; " & "Predicted Return"
                If .Fields("role_actual_dispatch_date") = True Then Me.cbo_dates.AddItem "role_actual_dispatch_date" & "; " & "Dispatch to Customer"
                If .Fields("role_received_by_customer") = True Then Me.cbo_dates.AddItem "role_received_by_customer" & "; " & "Received by Customer"

        End With
        rs.Close
        db.Close
        Set rs = Nothing
        Set db = Nothing
    End Sub

Private Sub saverecord()
        Dim sql As String, db As DAO.Database, rs As Recordset
        Set db = CurrentDb
        sql = "SELECT tbl_vr.*, tbl_customer.customer_name, tbl_customer.customer_number, tbl_customer.customer_d_number, tbl_customer.customer_email " _
            & "FROM tbl_vr INNER JOIN tbl_customer ON tbl_vr.customer_id = tbl_customer.customer_id " _
            & "WHERE tbl_vr.vr_id=" & get_current_vr_id()
        Set rs = db.OpenRecordset(sql, dbOpenDynaset)
        With rs
        .Edit
            .Fields("vr_reference") = txt_vr_reference
            .Fields("vr_external_reference") = txt_external_reference
            .Fields("vr_project") = txt_vr_project
            .Fields("part_master_id") = cbo_part_master_id
            .Fields("part_master_revised_id") = cbo_part_master_revised_id
            .Fields("vr_creation_date") = txt_vr_creation_date
            .Fields("vr_anticipated_dispatch") = txt_vr_anticipated_dispatch
            .Fields("vr_quote_to_customer") = txt_vr_quote_to_customer
            .Fields("vr_quote_acceptance") = txt_vr_quote_acceptance
            .Fields("vr_quote_rejection") = txt_vr_quote_rejection
            .Fields("vr_received_at_mbda") = txt_vr_received_at_mbda
            .Fields("vr_sent_to_repairer") = txt_vr_sent_to_repairer
            .Fields("vr_received_from_repairer") = txt_vr_received_from_repairer
            .Fields("vr_predicted_return_date") = txt_vr_predicted_return_date
            .Fields("vr_actual_dispatch_date") = txt_vr_actual_dispatch_date
            .Fields("vr_received_by_customer") = txt_vr_received_by_customer
            .Fields("vr_serial_no") = txt_vr_serial_no
            .Fields("customer_name") = txt_customer_name
            .Fields("user_id") = txt_user_id
            .Fields("customer_email") = txt_customer_email
            .Fields("customer_number") = txt_customer_number
            .Fields("customer_d_number") = txt_customer_number_d
        .Update
        End With
        If Not txt_vr_creation_date = "" Or Not IsNull(txt_vr_creation_date) Then
            Call UPDATE_chevron("vr_creation_date", global_CURRENT_VR_ID, False)
        Else
            Call UPDATE_chevron("vr_creation_date", global_CURRENT_VR_ID, True)
        End If
        If Not txt_vr_predicted_return_date = "" Or Not IsNull(txt_vr_predicted_return_date) Then
            Call UPDATE_chevron("vr_predicted_return_date", global_CURRENT_VR_ID, False)
        Else
            Call UPDATE_chevron("vr_predicted_return_date", global_CURRENT_VR_ID, True)
        End If
        If Not txt_vr_quote_acceptance = "" Or Not IsNull(txt_vr_quote_acceptance) Then
            Call UPDATE_chevron("vr_quote_acceptance", global_CURRENT_VR_ID, False)
        Else
            Call UPDATE_chevron("vr_quote_acceptance", global_CURRENT_VR_ID, True)
        End If
        If Not txt_vr_quote_rejection = "" Or Not IsNull(txt_vr_quote_rejection) Then
            Call UPDATE_chevron("vr_quote_rejection", global_CURRENT_VR_ID, False)
        Else
            Call UPDATE_chevron("vr_quote_rejection", global_CURRENT_VR_ID, True)
        End If
        If Not txt_vr_quote_to_customer = "" Or Not IsNull(txt_vr_quote_to_customer) Then
            Call UPDATE_chevron("vr_quote_to_customer", global_CURRENT_VR_ID, False)
        Else
            Call UPDATE_chevron("quote_to_customer", global_CURRENT_VR_ID, True)
        End If
        If Not txt_vr_received_at_mbda = "" Or Not IsNull(txt_vr_received_at_mbda) Then
            Call UPDATE_chevron("vr_received_at_mbda", global_CURRENT_VR_ID, False)
        Else
            Call UPDATE_chevron("vr_received_at_mbda", global_CURRENT_VR_ID, True)
        End If
        If Not txt_vr_received_by_customer = "" Or Not IsNull(txt_vr_received_by_customer) Then
            Call UPDATE_chevron("vr_received_by_customer", global_CURRENT_VR_ID, False)
        Else
            Call UPDATE_chevron("vr_received_by_customer", global_CURRENT_VR_ID, True)
        End If
        If Not txt_vr_sent_to_repairer = "" Or Not IsNull(txt_vr_sent_to_repairer) Then
            Call UPDATE_chevron("vr_sent_to_repairer", global_CURRENT_VR_ID, False)
        Else
            Call UPDATE_chevron("vr_sent_to_repairer", global_CURRENT_VR_ID, True)
        End If
        If Not txt_vr_anticipated_dispatch = "" Or Not IsNull(txt_vr_anticipated_dispatch) Then
            Call UPDATE_chevron("vr_anticipated_dispatch", global_CURRENT_VR_ID, False)
        Else
            Call UPDATE_chevron("vr_anticipated_dispatch", global_CURRENT_VR_ID, True)
        End If
        If Not txt_vr_predicted_return_date = "" Or Not IsNull(txt_vr_predicted_return_date) Then
            Call UPDATE_chevron("vr_predicted_return_date", global_CURRENT_VR_ID, False)
        Else
            Call UPDATE_chevron("vr_predicted_return_date", global_CURRENT_VR_ID, True)
        End If
            If Not txt_vr_actual_dispatch_date = "" Or Not IsNull(txt_vr_actual_dispatch_date) Then
            Call UPDATE_chevron("vr_actual_dispatch_date", global_CURRENT_VR_ID, False)
        Else
            Call UPDATE_chevron("vr_actual_dispatch_date", global_CURRENT_VR_ID, True)
        End If
        If Not txt_vr_received_from_repairer = "" Or Not IsNull(txt_vr_received_from_repairer) Then
            Call UPDATE_chevron("vr_received_from_repairer", global_CURRENT_VR_ID, False)
        Else
            Call UPDATE_chevron("vr_received_from_repairer", global_CURRENT_VR_ID, True)
        End If


    Forms![frm_open_repairs].Requery

End Sub

以上是表单的全部代码。

【问题讨论】:

你到底想做什么? 【参考方案1】:

似乎“未绑定的表单”,无法处理 dirty 属性,因为它始终是干净的。

所以你可以在表单模块的顶部添加一个变量并使用它。

【讨论】:

这是一个很好的答案。一个简单的事实是,脏标志仅适用于绑定表单。

以上是关于我正在尝试在我的未绑定表单上使用脏选项。我该怎么做呢?以下是表单的所有代码。在访问 2010 [关闭]的主要内容,如果未能解决你的问题,请参考以下文章

我的未绑定(菜单)子表单出现在数据表中

使用主窗体中的未绑定文本框过滤 Microsoft Access 中的子窗体

如何在我的 Access 2016 数据库中隐藏菜单栏并仅显示正在运行的表单

如何隐藏博客帖子表单主页

在子报表的子窗体中引用未绑定的文本框

用于过滤子表单数据表的未绑定文本框