Results 1 to 7 of 7
  1. #1
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658

    Is pausing VBA code in one form possible?

    I have two forms, A and B


    A is a form for entering a record, let's say customers
    B is a form for searching for records on which A is based and can return an ID for a customer

    I'm not even sure this is possible:
    I need the procedure in A that calls B to stop and wait for a value to be calculated and returned from form B (via a global variable)
    When B closes, A can get the variable and continue with what it needs to do.

    I've searched, and some suggest making B modal, but that doesn't work,
    the procedure in A continues on its merry way as formb B opens.
    Others suggest using an on error goto, but this situation doesn't have an error to trap.

    I guess I could do a loop in A until a condition is met, but I'm thinking there must be a more elegant way without running looping code.
    (I'm not sure this would work either, as then I need a "release" from the running code in form A to let Form B do its thing)

    Can there be a "conditional pause" in VBA in form A until form B closes?

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Opening the form in Dialog mode will achieve the result you require

    Code:
    Code
    More Code
    DoCmd.OpenForm "YourFormB", , , , acFormEdit, acDialog, sMyOpenArgs
    ThisCodeHere won't run until YourFormB is closed
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    @ Minty Cool and thanks for the quick reply. I'll give it a test and dig deeper into all the options of DoCmd.OpenForm (I proabbly read it before but it didn't register as for the purpose of acDialog).
    I am opening instances of the form, so it gets tricky, so I'll have to see its impact on other form A that can be open.

  4. #4
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    From memory if any form is opened as a dialog nothing else (In Access) can receive the focus or operate, similar to a error message or msgbox.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    Here's a write up from DBG re: Modal vs. Dialog

    http://thedbguy.blogspot.com/2016/02...log-forms.html
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  6. #6
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    I've tested the acDialog method, and it seems to work.
    The problem I'm running into is that the form is then modal and popup as best as I can tell. And popup isn't a property that can be altered.
    One of those makes it so the user can't resize the form. I need resizing because I'm having an issue with Access resizing forms (making data/buttons not visible in the form) for a yet to be discovered reason.

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Just curious-- Is it possible that you can tell (because of user, or process or XX) in advance that you will need to resize a form?
    Isladogs has some form resizer code/articles that may be applicable, if you can tell in advance and and set up the logic.

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

Similar Threads

  1. Pausing code until a condition is met
    By S2000magician in forum Programming
    Replies: 6
    Last Post: 09-26-2019, 10:57 AM
  2. Pausing code on one form until another form is closed?
    By S2000magician in forum Programming
    Replies: 3
    Last Post: 08-17-2019, 10:05 PM
  3. acDialog not pausing code
    By mredmond13 in forum Programming
    Replies: 8
    Last Post: 07-08-2018, 01:31 PM
  4. Pausing OpenReport
    By EES in forum Reports
    Replies: 5
    Last Post: 06-15-2011, 05:30 PM
  5. Pausing a Macro
    By Rick West in forum Programming
    Replies: 0
    Last Post: 03-17-2010, 10:29 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