Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding calendar created problems

Status
Not open for further replies.

PhilWB

Technical User
Sep 15, 2004
21
0
0
AU
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
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
This is the form for the fields on the main form
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
EndDate update is just a little different in msgbox etc, but has same Requery commands.
Any help or thoughts greatly appreciated
Thanks, Phil
 
How are ya PhilWB . . . . .
Microsoft said:
[blue]Writing to a control thru VBA [purple]does not trigger the AfterUpdate Event![/purple][/blue]
You'll have to requery your subforms in your code . . .

Calvin.gif
See Ya! . . . . . .
 
Thank you AceMan,
Knew it would be something simple that I was overlooking
happy.gif

Will get to learn all of this stuff one day, just got to work out on how to live to 125 !
Take care, Phil
 
So you think you would have learnt it all by the time you are 125? Most of us are well past that and are still learning [smile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top