Glitched addressing, or just addressing controls incorrectly?

J

Jaazaniah

I have a continuous subform for scheduling based on a list of dates in
the main form. The rest of the structure of the database has been
coded around the date and time of a given scheduled event to be in a
single field (dtDateTime). Because of the way this form is laid out,
the actual dtDateTime and dtDate (breaking out just the date portion
of dtDateTime) are hidden controls that are supposed to pick up the
master form's date for defaults.

My problem lies in the separated Time control. Here's the GotFocus/
LostFocus:

Private Sub Time_GotFocus()
Me.Time.ControlSource = ""
Me.Time.Text = Format([dtDateTime], "hh:nn")
Me.Time.SelStart = 0
Me.Time.SelLength = Len(Me.Time)
End Sub

Private Sub Time_LostFocus()
If Me.Date = 0 Then Me.dtDateTime = Forms!frmAppointmentDates!dtDates
Me.dtDateTime = CDate(Me.Date & " " & Me.Time)
Me.Time.ControlSource = "=CDate(Format([dtDateTime],""hh:nn""))"
End Sub

This was supposed to handle the fact that time isn't really a separate
field without allowing the user to alter the date in the subform.
However, to my dismay, this seems to be setting the displayed Time for
ALL displayed records as the time for the current record on LostFocus.
OnCurrent events seem to display the control correctly with no help
from code, so what am I doing wrong here? Thanks.
 
J

Jaazaniah

I have a continuous subform for scheduling based on a list of dates in
the main form. The rest of the structure of the database has been
coded around the date and time of a given scheduled event to be in a
single field (dtDateTime). Because of the way this form is laid out,
the actual dtDateTime and dtDate (breaking out just the date portion
of dtDateTime) are hidden controls that are supposed to pick up the
master form's date for defaults.

My problem lies in the separated Time control. Here's the GotFocus/
LostFocus:

Private Sub Time_GotFocus()
Me.Time.ControlSource = ""
Me.Time.Text = Format([dtDateTime], "hh:nn")
Me.Time.SelStart = 0
Me.Time.SelLength = Len(Me.Time)
End Sub

Private Sub Time_LostFocus()
If Me.Date = 0 Then Me.dtDateTime = Forms!frmAppointmentDates!dtDates
Me.dtDateTime = CDate(Me.Date & " " & Me.Time)
Me.Time.ControlSource = "=CDate(Format([dtDateTime],""hh:nn""))"
End Sub

This was supposed to handle the fact that time isn't really a separate
field without allowing the user to alter the date in the subform.
However, to my dismay, this seems to be setting the displayed Time for
ALL displayed records as the time for the current record on LostFocus.
OnCurrent events seem to display the control correctly with no help
from code, so what am I doing wrong here? Thanks.

On a second look, running an extra Me.Refresh in the lost focus seems
to fix the problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top