vbams-accesseventssubforms

Change event in access won't work when cycling through records


I currently have a form with two sub-forms, In one sub-form called Customer Addresses I have a textbox that contains the address table primary key. I put buttons on this form to cycle to next or previous records, and when I cycle through these records I can see my different address Ids cycling in the text box.

Now when my addressIDs are being cycled I want that value to automatically update another textbox in another sub-form called CustomerContacts. I added some code to the change and the update events but had no success.

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

End Sub

The references in the above code are correct. I tested this code with a combobox in which I actually hit the drop down arrow and selected a value and it successfully updated the other text box in the other subform.

So there is something I am missing here, when cycling through the records it will not trigger the change or the update events, so I am wondering how I can get around all this.


Solution

  • Converted Forms macros to visual basic. Now my commands buttons that were selecting the next and previous records are in vba code. Next Take the code for the text box you want updated and put it under the line that selects the records.

    '------------------------------------------------------------
    ' 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