Event associated with combobox don't trigger (1 Viewer)

LukeSky

Registered User.
Local time
Today, 15:01
Joined
Aug 4, 2016
Messages
12
Hi, all.

I have two forms, one mainform and another form, form2, that is open from mainform.

In mainform, has one combobox and after inserting data, it trigger event executing macro "test" for showing a msgbox.

In form2, has another combobox that after inserting data, it trigger event executing vba code for changing data mainform's combobox. When close form2 for coming back to mainform, the macro is not triggered in event AfterUpdate.

My question is how I could do for forcing execute that event.

Is necessary that in vba code inserting?:

Code:
docmd.runMacro "test.msg"

If I was using vba for controling that combobox, I know that could use "cbo_AfterUpdate" but it is not my doubt. I would just like to know if there would be another way to force the execution of event AfterUpdate that has one "macro" instead of "Event Procedure".

I attach example database. Thanks in advance and forgive me my english that is not my native language.
 

Attachments

  • CCO.mdb
    1 MB · Views: 62
Last edited:

LukeSky

Registered User.
Local time
Today, 15:01
Joined
Aug 4, 2016
Messages
12
Ok, I found like do it.

I attach database with solution, hope that be useful for someone.

Thanks. Regards.
 

Attachments

  • CCO_Solution.mdb
    244 KB · Views: 57
Last edited:

tmguru

Registered User.
Local time
Today, 15:01
Joined
Apr 8, 2018
Messages
19
Hi LukeSky,

Can you please just post the description of the method you used instead of having to open your database.

Thanks!
 

LukeSky

Registered User.
Local time
Today, 15:01
Joined
Aug 4, 2016
Messages
12
Hi LukeSky,

Can you please just post the description of the method you used instead of having to open your database.

Thanks!

Yes, no problem.

The MAINFORM form, has combobox named 'cboData' that has linked to event AfterUpdate
macro 'test.msg'. And command button that open form named 'Form2'

Inside this macro, there are two submacros 'msg' and 'open'. Submacro 'msg' show msgbox with test message, and 'open' open form named 'Form2'.

When 'Form2' is open/loaded, can see other combobox named 'cboInput', and command button 'Exit' that coming back to mainform.

Code of Form2:

Code:
Private Sub cboInput_AfterUpdate()
    MsgBox "Me.cboInput: " & Me.cboInput
    MsgBox "Forms!mainform.cboData: " & Forms!mainform.cboData

End Sub

Private Sub Comando5_Click()
On Error GoTo Err_Comando5_Click

    DoCmd.Close


Exit_Comando5_Click:
    Exit Sub

Err_Comando5_Click:
    MsgBox Err.Description
    Resume Exit_Comando5_Click
    
End Sub


Private Sub Form_Close()
    'MsgBox Me.cboInput
    Me.Visible = False
    If CurrentProject.AllForms("MAINFORM").IsLoaded Then
        Forms!mainform.cboData.SetFocus
        
        If Not IsNull(Me.cboInput) Then
            Forms!mainform.cboData.Text = Me.cboInput
        End If
    End If

End Sub

If you change value of combobox 'cboInput' of 'Form2', when coming back to 'mainform' its combobox 'cboData' will be updated with value selected in combobox 'cboInput' . At the moment, event AfterUpdate of combobox 'cboData' is executing shows msgbox.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:01
Joined
May 7, 2009
Messages
19,230
On the Close event of the form the value of all controls are destroyed. Use the unload event instead where all the vakues are still intact.
 

Users who are viewing this thread

Top Bottom