Results 1 to 7 of 7
  1. #1
    JJeffH is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Apr 2020
    Posts
    30

    Control the "X" action on a form (queryclose in Excel VBA)

    I have a macro called “frmM_Activity: cmdSwitchboard:On Click” embedded in a button that closes the active form and opens the switchboard form.

    I want to call that macro when the user clicks the Close Button (X) on the form. This is done with QueryClose in Excel, but I don’t know how to do it in Access.



    -Jeff

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,603
    Try form OnClose event.

    I normally disable the X close and create a custom button for user to close.
    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.

  3. #3
    JJeffH is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Apr 2020
    Posts
    30
    I've only just started using Access embedded macros, so I don't understand the syntax. I tried RunMacro in a macro on the Form On Close event. The documentation on RunMacro says the builder will have a list of macros in the database, but the only option I get in the Macro Name field is "RunMacro". In the Action Catalog, under In This Database, I see the macro I'm looking for as "cmdSwitchboard.OnClick", but when I type that in the Macro Name field it isn't recognized.

    1. Any idea why the Macro Builder isn't giving me any macro names?

    2. I thought I could change the button action to VBA code then refer to that with VBA, but I couldn't find a form Unload or Close event in VBA. (The button macro closes the current form and opens the Switchboard.)

    3. How do you disable the X?

    - Jeff

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,603
    I don't use macros, only VBA.
    There certainly are form OnUnload and OnClose events.

    Check out form properties:

    ControlBox
    CloseButton
    MinMaxButtons
    BorderStyle
    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.

  5. #5
    JJeffH is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Apr 2020
    Posts
    30
    I am much more familiar with Excel VBA. In Excel I would do the tasks I'm trying to accomplish in Access like this in the frmM_Activity code:

    Code:
    Option Explicit
    
    Private Sub cmdSwitchboard_Click()
         Unload Me
         Load Switchboard
         Switchboard.Show
    End Sub
    
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
         If CloseMode = 0 Then cmdSwitchboard_Click
    End Sub

    I did see the OnUnload and OnClose events, but they don't sound like commands to Unload or Close, rather just "do this when you do close", which seems like a very different syntax.

    I'm trying to make a transition from Excel to Access so I wonder if you could help me understand how to transfer my understanding of this sequence of events. Sorry to say, I think I need explicit instructions.

    Thanks,
    - Jeff

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,603
    I don't understand your requirement well enough nor anything about your business processes to be explicit.

    I normally disable the X close and create a custom button on form for user to "Close".

    I have never used unload event and close event rarely.
    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.

  7. #7
    JJeffH is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Apr 2020
    Posts
    30
    Ok. Thanks for your input, June7. I'm using the work-around of disabling the close button, and that's ok for now.

    - Jeff

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

Similar Threads

  1. "Close form" action does not release table
    By TFisher in forum Programming
    Replies: 8
    Last Post: 10-23-2022, 11:54 AM
  2. Replies: 4
    Last Post: 10-02-2019, 04:58 AM
  3. Replies: 3
    Last Post: 09-27-2015, 12:29 PM
  4. Replies: 1
    Last Post: 09-07-2015, 08:00 AM
  5. Replies: 1
    Last Post: 07-10-2015, 06:33 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