MS-Access - 如何在LostFocus事件之前触发数据插入?

时间:2010-07-28 16:13:10

标签: tsql ms-access vba

我有一个在控件的AfterUpdate事件上运行的过程:

Private Sub cmdDelCountry_AfterUpdate()

Dim strID As String
strID = Me.ID
Dim strCase As String
strCase = 1

Dim cmdCommand As New ADODB.Command

With cmdCommand
    .ActiveConnection = CurrentProject.Connection
    .CommandType = adCmdStoredProc
    .CommandText = "uspSalesOrderHead_UPDATE"

        '@RowID
        .Parameters("@RowID").Value = strID

        '@Case
        .Parameters("@Case").Value = strCase

    .Execute

End With

End Sub

该过程执行存储的SQL Server过程以处理服务器上的某些数据:

ALTER PROCEDURE uspSalesOrderHead_UPDATE

(
    @RowID int,
    @Case int
)

AS

IF @Case = 1 /* Delivery Country Select */

    BEGIN
        /* Update Order Head table */
        UPDATE dbo.tblSalesOrderHead
        SET dbo.tblSalesOrderHead.txtRegionCode     = dbo.tblSettingCountryCode.txtRegionCode,
            dbo.tblSalesOrderHead.txtCurrencyCode   = dbo.tblSettingCountryCode.txtCurrencyCode,
            dbo.tblSalesOrderHead.txtLanguageCode   = dbo.tblSettingCountryCode.txtLanguageCode
        FROM    dbo.tblSalesOrderHead
        INNER JOIN dbo.tblSettingCountryCode ON dbo.tblSalesOrderHead.txtDelCountry = dbo.tblSettingCountryCode.txtCountryCode
        AND     dbo.tblSalesOrderHead.ID            = @RowID;

        /* Update Order Line table */
        UPDATE  dbo.tblSalesOrderLine
        SET dbo.tblSalesOrderLine.txtRegionCode  = dbo.tblSalesOrderHead.txtRegionCode, 
            dbo.tblSalesOrderLine.txtCurrencyCode    = dbo.tblSalesOrderHead.txtCurrencyCode
        FROM    dbo.tblSalesOrderLine
        INNER JOIN dbo.tblSalesOrderHead ON dbo.tblSalesOrderLine.intOrderNo = dbo.tblSalesOrderHead.ID
        AND     dbo.tblSalesOrderLine.intOrderNo         = @RowID;
    END

问题是控件的(cmdDelCountry)值在存储的SQL过程请求之前没有插入到表(dbo.tblSalesOrderHead)中: INNER JOIN dbo.tblSettingCountryCode ON < / em> dbo.tblSalesOrderHead.txtDelCountry = dbo.tblSettingCountryCode.txtCountryCode

如何在执行存储过程之前插入数据?

1 个答案:

答案 0 :(得分:3)

您可以使用(在表单上)

 If Me.Dirty Then Me.Dirty = False

要强制保存,但最好在更新事件后考虑表单,而不是控件。