访问记录时,访问中的更改事件将不起作用

时间:2017-01-03 14:46:56

标签: vba ms-access events subforms

我目前有一个包含两个子表单的表单,在一个名为Customer Addresses的子表单中,我有一个包含地址表主键的文本框。我把这个表单上的按钮循环到下一个或上一个记录,当我循环浏览这些记录时,我可以在文本框中看到我的不同地址ID循环。

现在,当我的addressID被循环时,我希望该值自动更新另一个名为CustomerContacts的子表单中的另一个文本框。我在更改和更新事件中添加了一些代码,但没有成功。

Private Sub Text0_Change()
        Me.Parent!ContactInformation.Form!ContactInformation_Address.Value = Text0.Value

End Sub

上述代码中的引用是正确的。我用一个组合框测试了这个代码,其中我实际上按下了下拉箭头并选择了一个值,它成功更新了另一个子窗体中的另一个文本框。

所以我在这里缺少一些东西,当在记录中循环时它不会触发更改或更新事件,所以我想知道如何绕过这一切。

1 个答案:

答案 0 :(得分:0)

将转换的表单宏转换为visual basic。现在,我选择下一个和上一个记录的命令按钮都是vba代码。下一步获取要更新的文本框的代码,并将其放在选择记录的行下。

'------------------------------------------------------------
' Command24_Click
'
'------------------------------------------------------------
Private Sub Command24_Click()
On Error GoTo Command24_Click_Err

    On Error Resume Next
    DoCmd.GoToRecord , "", acPrevious
    Me.Parent!ContactInformation.Form!ContactInformation_Address.Value = Text0.Value
    If (MacroError <> 0) Then
        Beep
        MsgBox MacroError.Description, vbOKOnly, ""
    End If


Command24_Click_Exit:
    Exit Sub

Command24_Click_Err:
    MsgBox Error$
    Resume Command24_Click_Exit

End Sub


'------------------------------------------------------------
' Command25_Click
'
'------------------------------------------------------------
Private Sub Command25_Click()
On Error GoTo Command25_Click_Err

    ' _AXL:<?xml version="1.0" encoding="UTF-16" standalone="no"?>
    ' <UserInterfaceMacro For="Command24" xmlns="http://schemas.microsoft.com/office/accessservices/2009/11/application"><Statements><Action Name="OnError"/><Action Name="GoToRecord"><Argument Name
    ' _AXL:="Record">Previous</Argument></Action><ConditionalBlock><If><Condition>[MacroError]&lt;&gt;0</Condition><Statements><Action Name="MessageBox"><Argument Name="Message">=[MacroError].[Description]</Argument></Action></Statements></If></ConditionalBlo
    ' _AXL:ck></Statements></UserInterfaceMacro>
    On Error Resume Next
    DoCmd.GoToRecord , "", acNext
    Me.Parent!ContactInformation.Form!ContactInformation_Address.Value = Text0.Value
    If (MacroError <> 0) Then
        Beep
        MsgBox MacroError.Description, vbOKOnly, ""
    End If


Command25_Click_Exit:
    Exit Sub

Command25_Click_Err:
    MsgBox Error$
    Resume Command25_Click_Exit

End Sub
相关问题