Results 1 to 2 of 2
  1. #1
    NumbersRock is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2022
    Posts
    2

    Exclamation VBA: Execute Code When closing form to refresh time

    I have a form "AddClass" that pops up to add a "Class" number to the Main form that is behind it. THe Class number is in a ComboBox.
    When adding the Class I want it to automatically update the Class Combobox with the most recent number and have it selected.

    The class number updates with the code below but there are 2 fields next to it for date and time, that still show the previously selected date and time


    Code:
    Private Sub Form_Close()
    If Forms!frmMainForm!cmbChooseClass >= 0 Then
        
    With Forms!frmMainForm!cmbChooseClass
        .Value = .ItemData(.ListCount - 1)
    End With
    
    Else
    
    End If
    
    End Sub



    On the Main form if I choose the Class number by clicking it in the Combo Drop down it does update the date and time.
    Below is the code that makes that work.
    I am trying to adapt the code to work in


    Code:
    Private Sub cmbChooseClass_AfterUpdate()
    
          txtDateOpened = DLookup("[Date Opened]", "qryClientClass", "[qryClientClass].[ClassNumber]=" & [cmbChooseClass])
          txtStarted = DLookup("[Time Opened]", "qryClientClass", "[qryClientClass].[ClassNumber]=" & [cmbChooseClass])
          txtClassRecordNumber = DLookup("[RecordID]", "qryClientClass", "[qryClientClass].[ClassNumber]=" & [cmbChooseClass])
          Me![tblProbes subform].Form.Requery
    End Sub
    Any help would be appreciated!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,943
    Include date and time fields as columns in combobox RowSource then have textboxes reference those columns by index for display. If value is in column 2, its index is 1. =cmbChooseClass.Column(1)

    If the Class number is saved to record, associated date and time should not need to be saved.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Closing form with code, still saves changes
    By Perceptus in forum Programming
    Replies: 5
    Last Post: 06-03-2020, 03:11 PM
  2. Replies: 6
    Last Post: 03-03-2017, 08:17 AM
  3. Replies: 6
    Last Post: 01-06-2015, 12:37 PM
  4. Replies: 4
    Last Post: 07-07-2014, 10:47 AM
  5. Don't want to save forms on Refresh or closing
    By accesscoder in forum Forms
    Replies: 5
    Last Post: 09-25-2010, 12:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums