Results 1 to 3 of 3
  1. #1
    Historypaul is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    64

    Requerying on close of dialog form - optional?

    I use a very typical setup a lot. I have the information displayed, but uneditable and there is a "new" button at the top of the list or form if the user wants to add something new. Very simply, the code is DoCmd.OpenForm "blah blah blah", after which, there is a Me.Requery.



    What I'd really like to do is skip the requery if the user didn't add a new record on the form that they opened... I have it currently, where the user just enters any new info they want, and hit the corner close button - not a dual "OK/Cancel" arrangement. But even if I did have a dual OK/Cancel button arrangement on my popup, how would I let the main form know which was pressed so it could determine whether or not a requery was necessary? Is there a simply way to pass a variable from the open dialog window back to the procedure kind of like passing openargs from the form to the dialog initially? I could then just use the "After Insert" event of my dialog window to set the state of that variable (probably true/false) if the user does actually add a record. Any ideas?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    No built-in way to pass a variable back, but you could set a global variable and test that.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Rawb is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    While you can pass variable information INTO another Form (for example, when you click a button to open a Form, you could pass information), you can't really return anything back the other way.

    In this instance, however, I think we can simulate it by just having the OK button on your popup Form perform the Requery on your main Form.

    The following code snippit makes several assumptions:
    • Your main Form is called frmSwitchboard.
    • Your popup form is called frmAddRec.
    • The "OK" Button on frmAddRec is called btnOK.
    • You only call frmAddRec from frmSwitchboard.


    Example code:
    Code:
    Private Sub btnOK_Click
        Forms!frmSwitchboard.Requery
        DoCmd.Close acForm, Me.Form.Name
    End Sub
    If you happen to open frmAddRec from multiple "main" Forms, you can still do it, but the Requery portion of the code is a little more complex.

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

Similar Threads

  1. Close Dialog Box instead of Close App
    By ccchan in forum Access
    Replies: 4
    Last Post: 03-19-2014, 08:34 AM
  2. Replies: 4
    Last Post: 01-31-2014, 11:47 AM
  3. Refreshing the form vs. requerying
    By Access_Novice in forum Forms
    Replies: 9
    Last Post: 01-01-2014, 07:24 PM
  4. Replies: 2
    Last Post: 10-23-2012, 12:18 PM
  5. Replies: 6
    Last Post: 10-15-2012, 01:49 PM

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