I have added a calendar that opens as a pop up to change dates on a main form that has two linked subforms. Now my subforms do not update after the calendar has done its job and changed the dates. Form still works if I enter the dates into the fields, so what am I missing.
This is the calendar form code
This is the form for the fields on the main form
EndDate update is just a little different in msgbox etc, but has same Requery commands.
Any help or thoughts greatly appreciated
Thanks, Phil
This is the calendar form code
Code:
Option Compare Database
Option Explicit
Public Sub SetControl(ctlToUpdate As Control)
Dim strActiveObjectName As String
On Error GoTo SetControl_Error
strActiveObjectName = Application.CurrentObjectName & "_Calendar1_SetControl"
' Reset the "control set" public flag
intSet = False
' First, validate the kind of control passed
Select Case ctlToUpdate.ControlType
' Text box, combo box, and list box are OK
Case acTextBox, acListBox, acComboBox
Case Else
MsgBox "Invalid control passed to the Calendar."
DoCmd.Close acForm, Me.Name
End Select
' Save the pointer to the control to update
Set ctlThisControl = ctlToUpdate
' Set the flag to indicate we got the pointer
intSet = True
' Save the "current" value of the control
varDate = ctlToUpdate.Value
DoEvents
' Make sure we got a valid date value
If varType(varDate) <> vbDate Then
' If not, set the default to today
Me!Calendar1.Value = Date
Else
' Otherwise, set the date to the one in the control
Me!Calendar1.Value = varDate
End If
SetControl_Exit:
Exit Sub
SetControl_Error:
DoCmd.Hourglass False
Application.Echo True
MsgBox "An error has occured in " & strActiveObjectName & ". @@" _
& "Error number " & Err.Number & ": " & Err.Description _
& vbCrLf & vbCrLf & "If this problem persists, note the error message and " _
& "call your programmer.", , "Ooops . . . (unexpected error)"
DoCmd.Close acForm, Me.Name
Resume SetControl_Exit
End Sub
Private Sub Calendar1_DblClick()
Dim strActiveObjectName As String
On Error GoTo ProcErr
strActiveObjectName = Application.CurrentObjectName & "_Calendar1_DblClick"
'
DoCmd.Close
ProcExit:
Exit Sub
ProcErr:
DoCmd.Hourglass False
Application.Echo True
MsgBox "An error has occured in " & strActiveObjectName & ". @@" _
& "Error number " & Err.Number & ": " & Err.Description _
& vbCrLf & vbCrLf & "If this problem persists, note the error message and " _
& "call your programmer.", , "Ooops . . . (unexpected error)"
Resume ProcExit
End Sub
Private Sub Form_Close()
Dim strActiveObjectName As String
On Error GoTo ProcErr
strActiveObjectName = Application.CurrentObjectName & "_Form_Close"
'
' Make sure we got a valid control to point to
If intSet Then
' OK - check to see if value changed
If varDate = Me!Calendar1.Value Then
' Doing a reverse test here because
' if we were passed a Null, it will not compare equal to anything
Else
ctlThisControl.Value = Me!Calendar1.Value
End If
End If
ProcExit:
Exit Sub
ProcErr:
DoCmd.Hourglass False
Application.Echo True
MsgBox "An error has occured in " & strActiveObjectName & ". @@" _
& "Error number " & Err.Number & ": " & Err.Description _
& vbCrLf & vbCrLf & "If this problem persists, note the error message and " _
& "call your programmer.", , "Ooops . . . (unexpected error)"
Resume ProcExit
End Sub
Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click
DoCmd.Close
Exit_cmdClose_Click:
Exit Sub
Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click
End Sub
Code:
Private Sub StartDate_AfterUpdate()
If StartDate > EndDate Then
MsgBox "From Date must be prior to To Date, please check.", , "Date Error"
Me.StartDate.Value = Me.EndDate.Value - 7
Me.StartDate.SetFocus
ElseIf StartDate <= EndDate Then
Me.frmSuppSub1.Requery
Me.frmSuppSub2.Requery
End If
End Sub
Any help or thoughts greatly appreciated
Thanks, Phil