• Field not updating when pop-up calendar is used

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Field not updating when pop-up calendar is used

    Author
    Topic
    #462547

    Hi,

    I have a sub-form in a form from which users can enter multiple dates. As they enter dates, it updates a field on the main form with the ‘latest’ date. This is the code I’m using on ‘After-Update’ function of the field in the sub-form:

    Private Sub CabAppDate_AfterUpdate()
    Forms![ProgramMovements].LatestAIPDate = Me.CabAppDate
    End Sub

    I want to use a pop-up calendar which users can enter the date with, and I’ve downloaded a sample module/form from a website. The calendar works ok (ie, it pops up and allows users to enter the date), but if they enter the date through the calendar, it now doesn’t update the ‘latest’ date on the main form. I’m very new to Access, so hopefully someone can help!

    Cheers,
    Jason

    Viewing 1 reply thread
    Author
    Replies
    • #1177676

      Welcome to the Lounge!

      The After Update event of CabAppDate only occurs when the user enters or modifies it directly. When the user selects a date in the popup form, the value of CabAppDate is set but its After Update event does not occur, and hence the date on the main form is not modified. So you will have to run the CabAppDate_AfterUpdate explicitly. How to do that depends on the way the popup form and the associated module work.

      • #1177677

        Welcome to the Lounge!

        The After Update event of CabAppDate only occurs when the user enters or modifies it directly. When the user selects a date in the popup form, the value of CabAppDate is set but its After Update event does not occur, and hence the date on the main form is not modified. So you will have to run the CabAppDate_AfterUpdate explicitly. How to do that depends on the way the popup form and the associated module work.

        Hi Hans,

        Thanks so much for the quick reply. I’m not much of a programmer, and have copied/pasted etc code from other databases and the web to get everything working! In the ‘On_Dbl_click’ part of the field, I’m calling this code:

        =PopupCalendar(Screen.ActiveControl)

        Which references the basCalendar module which contains this code:

        Option Compare Database ‘Use database order for string comparisons
        Option Explicit

        Const CALENDAR_FORM = “zsfrmCalendar”

        Type udDateType
        wYear As Integer
        wMonth As Integer
        wDay As Integer
        End Type

        Private Function isFormLoaded(strFormName As String)
        isFormLoaded = SysCmd(SYSCMD_GETOBJECTSTATE, A_FORM, strFormName)
        End Function

        Function PopupCalendar(ctl As Control) As Variant

        ‘ This is the public entry point.
        ‘ If the passed in date is Null (as it will be if someone just
        ‘ opens the Calendar form raw), start on the current day.
        ‘ Otherwise, start with the date that is passed in.

        Dim frmCal As Form
        Dim varStartDate As Variant

        varStartDate = IIf(IsNull(ctl.Value), Date, ctl.Value)
        DoCmd.OpenForm CALENDAR_FORM, , , , , A_DIALOG, varStartDate

        ‘ You won’t get here until the form is closed or hidden.

        ‘ If the form is still loaded, then get the final chosen date
        ‘ from the form. If it isn’t, return Null.

        If isFormLoaded(CALENDAR_FORM) Then
        Set frmCal = Forms(CALENDAR_FORM)
        ctl.Value = Format(DateSerial(frmCal!Year, frmCal!Month, frmCal!Day), “dd/mmm/yyyy”)
        DoCmd.Close A_FORM, CALENDAR_FORM
        Set frmCal = Nothing
        End If
        End Function

        Hope this helps!

        Cheers,
        Jason

        • #1177678

          Try the following:
          – Open the subform in design view.
          – Select the text box CabAppDate.
          – Activate the Event tab of the Properties window.
          – Click in the On Dbl Click box.
          – Select [Event Procedure] from the dropdown menu.
          – Click the button with three dots … to the right of the dropdown arrow.
          – Make the code look like this:

          Code:
          Private Sub CabAppDate_DblClick(Cancel As Integer)
            Call PopupCalendar(Screen.ActiveControl)
            Call CabAppDate_AfterUpdate
          End Sub

          – Switch back to Access.
          – Close and save the subform.

          The new On Dbl Click event procedure will first display the popup calendar, then force the After Update event procedure to run.

    • #1177683

      Yes, that worked! Thankyou so much for your quick replies!

      • #1177691

        You’re welcome! It was easy to help you because you provided all the relevant information needed!

    Viewing 1 reply thread
    Reply To: Field not updating when pop-up calendar is used

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: