As I suspected, this is one of those calendar designs that's pathologically
coupled to its caller. The code assumes it will write a value back to a
control on the caller's form using Forms(<formname>.Controls(<controlname>).
It would be far better if the calendar had no idea the nature of thing the
selected date is being written back to, and the caller doesn't need to know
how the calendar is implemented. The call would then look something like
this...
Private Sub Date_Complete_MouseDown(...
CalendarInput Me!Date_Complete
End Sub
Without knowing what the code on the calendar form itself looks like, I can't
tell you all of what the CalendarInput function would look like, and what the
code on the calendar form would look like, but part of it would probably look
something like this...
Public Sub CalendarInput(ByRef DateValue As Variant)
Const cstrFormName = "frmCalendar"
DoCmd.OpenForm FormName:=cstrFormName, _
WindowMode:=acDialog, _
OpenArgs:=DateValue
Dim frmCalendar As Access.Form
On Error Resume Next
Set frmCalendar = Forms(cstrFormName)
On Error Goto 0: Err.Clear
If frmCalendar Is Nothing Then Exit Sub
Dim varDateSelected As Variant
varDateSelected = frmCalendar!ocxCalendar.Value
Set frmCalendar = Nothing
DoCmd.Close acForm, cstrFormName
If IsObject(DateValue) then
'Write the selected value back to the default value property of
'the DateValue object passed.
Dim objDateValue As Object
Set objDateValue = DateValue
objDateValue = varDateSelected
Else
'Just return the value by reference to the variable supplied for
'DateValue.
DateValue = varDateSelected
End If
End Sub
Because we open the calendar form with acDialog, our code waits until the
calendar form is closed or hidden before it can continue. On the calendar
form, the code says Me.Visible = False after the user is done selecting a
value, so the calling code continues, but the form remains open for reading
the result. If the user cancels the selection, the form simply does
DoCmd.Close acForm, Me.Name to close itself, and the calling code knows that a
closed calendar form means there's no value to get.
On Fri, 10 Jun 2005 15:46:45 +1000, "Stinky Pete" <ca************@hotmail.com>
wrote:
Fair point ;-)
The code that is working on the form to pup up the calendar is ...
Private Sub Date_Complete_MouseDown(Button As Integer, Shift As Integer, X
As Single, Y As Single)
DoCmd.OpenForm "frmCalendar"
With Forms!frmCalendar
.txtFormName.Value = Me.Name
.txtControlName.Value = Me.ActiveControl.Name
If IsDate(Me.ActiveControl.Value) Then
.ocxCalendar.Value = Me.ActiveControl.Value
Else
.ocxCalendar.Value = Date
End If
End With
End Sub
and the code for the acutal calendar (which is a form) is ...
Private Sub cmdOK_Click()
On Error GoTo cmdOK_Click_err
Forms(Me.txtFormName.Value).Controls(Me.txtControl Name.Value).Value = _
Me.ocxCalendar.Value
cmdOK_Click_exit:
DoCmd.Close acForm, Me.Name
Exit Sub
cmdOK_Click_err:
Select Case Err.Number
Case 2450
MsgBox "You closed the form. Why?!?", vbCritical, "Error!"
Case Else
MsgBox "Well, that wasn't very bright!", vbCritical, "Error!"
End Select
Resume cmdOK_Click_exit
End Sub
"Steve Jorgensen" <no****@nospam.nospam> wrote in message
news:v6********************************@4ax.com.. . On Fri, 10 Jun 2005 14:59:53 +1000, "Stinky Pete"
<st*************@hotmail.com> wrote:
I've got a form that has been quite happily useing a pop up calendar to
enter dates. However I've had to amend the world and add the form as a
subform. To my frustration, the pop up calendar now does not work on the
subform. Each time I click on the field, instead of allowing the date to
pop into the field, I just get an error message asking me if I really want
to close the calendar pup up.
Suggestions ??
Stinky Pete
Without looking at the code, it's really hard to say, but you may have one
of
the many implementations of a calendar form that's written to try to look
back
into the form it's called from. If so, that's a nasty, circular
dependency
that should be removed, but without seeing exactly what you have, we can't
give you any concrete advice.