Change Event for a inactive form's control won't fire

  • Thread starter Thread starter William Benson
  • Start date Start date
W

William Benson

I have a button on a form which launches a second form having a calendar
control. The first form stays open. I set the calendar, and click a "Done"
button on the second form. In the click event (calendar form), I set a text
box (main form) equal to the selected date. So far, so good. Problem: The
_change event for the text box (first form) won't fire! As a workaround, I
tried to call some procedures on the first form and either that is not
possible or I have the wrong syntax.Can someone please help me out? THANK
YOU!!
 
I've had the same problem.

The only way I got round it was to use the LostFocus action, as follows:

'-----------------------------------------------------------------------------
-----------------

Private Sub NStartDate_DblClick(Cancel As Integer)

DoCmd.OpenForm ("frmCalendar")

End Sub


Private Sub NStartDate_LostFocus()

' Only way to check if user has entered a new date via the calendar
' - On Change & After Update events are not triggered

If Not IsNull(NStartDate.Value)) Then
.....
.....
End If

If IsFormLoaded("frmCalendar") Then DoCmd.Close acForm, "frmCalendar"

End Sub

'-----------------------------------------------------------------------------
 
I've had the same problem.

The only way I got round it was to use the LostFocus action, as follows:

'-----------------------------------------------------------------------------
-----------------

Private Sub NStartDate_DblClick(Cancel As Integer)

DoCmd.OpenForm ("frmCalendar")

End Sub


Private Sub NStartDate_LostFocus()

' Only way to check if user has entered a new date via the calendar
' - On Change & After Update events are not triggered

If Not IsNull(NStartDate.Value)) Then
.....
.....
End If

If IsFormLoaded("frmCalendar") Then DoCmd.Close acForm, "frmCalendar"

End Sub

'-----------------------------------------------------------------------------
 
Sorry, I do not understand this workaround and it is not expressed in the
terms I described

Form1, Form2 (has calendar control)

so I do not know what is losing focus in your solution, nor what field you
are referring to that the user has to move out of.
 
Hi William,

I'm not sure I follow your various references to first form, second
form, calendar form, and main form, but (assuming I've got a vague idea
what you're doing)

1) As Help says, the Change event of a textbox only fires when its Text
property is changed, not when its Value is changed. In fact the Text
property is only available when the textbox has the focus - which it
seems is not the case here.

2) You can't call a form's event procedures from outside the form (they
are all declared as Private). But you can create a method of the form
that calls an event procedure, e.g. by putting something like this in
the form's module:

Public Sub Call_txtXXX_Change()
txtXXX_Change
End Sub

and calling it with something like this:

Forms("OtherForm").Call_txtXXX_Change

But you may not need to do this: it sounds as if you should be opening
the calendar form in dialog mode. There's a sample database at
http://www.mvps.org/access/forms/frm0050.htm which shows how to use a
little calendar, as well as other examples elsewhere on the web.
 
Thanks

I had tried opening the calendar form both in dialog and non-dialog mode,
and in either case I could not cause the _change event to fire on the form
which called the dialog. With your suggestion I should be able to make it
work.

Thanks.
 
Back
Top