Results 1 to 3 of 3
  1. #1
    sgtclark is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2020

    Macro to close and open a form from last opened form ID

    I am trying to create a macro on a button that will close the form, store the last viewed record ID temparily, and the opens the form again displaying the last viewed record.

    Why you ask? The record source is a SharePoint list and I am running some queries in the macro on that record. But it will not allow them to run until you close the form and reopen it. I don't understand the why, but I know if I run the query after making changes it will not work unless I close the form and open it again.

    I tried having the macro save the record first then running the query, and that still doesn't work. The only thing I have found to work is to close it and reopen then the query will run perfectly. So I want to automate this step.

    OR can you set a temporary variable of the current record ID, close the form, and use the temporary variable to run the query without opening the form again? If so what is the best way to do this?

    Thank you
    Last edited by sgtclark; 04-30-2020 at 04:40 PM. Reason: Update

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    macros aren't great for doing this, but it can.

    'if form 1 is open:

    docmd.Openform "frm2"
    forms!frm2!txtID = forms!frm1!txtID
    docmd.close acform "frm1"

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Anchorage, Alaska, USA
    Maybe you can use this tip by Allen Browne "Return to the same record next time form is opened" will help you.
    "Veni, Vidi, Velcro"
    (I came; I saw; I stuck around.)

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

Similar Threads

  1. Replies: 2
    Last Post: 01-15-2020, 03:20 PM
  2. Replies: 5
    Last Post: 10-18-2016, 06:00 AM
  3. Replies: 4
    Last Post: 10-09-2014, 07:09 PM
  4. Replies: 1
    Last Post: 05-03-2012, 02:25 PM
  5. Can not close pop up form after second pop was opened
    By snoopy2003 in forum Programming
    Replies: 2
    Last Post: 03-09-2011, 02:56 AM

Tags for this Thread

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 - Senior Forums