Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Sep 2009
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    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.

  3. #3
    Star Lounger
    Join Date
    Sep 2009
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='793659' date='17-Sep-2009 11:56']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.[/quote]

    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

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    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.

  5. #5
    Star Lounger
    Join Date
    Sep 2009
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, that worked! Thankyou so much for your quick replies!

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You're welcome! It was easy to help you because you provided all the relevant information needed!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •