Access 2013 - Opening the last form or table that was accessed on start-up

I have an access 2013 database that is opening the last form or table that was accessed when it starts-up

I have a start-up form that runs a vba app to create a table on start-up then it closes the start-up form and opens a master form.

The start-up form is listed under the Display form in Current Database Options

code in the start-up form is

Private Sub Form_Close()
    DoCmd.OpenForm "0_MasterDataFrm", acNormal
End Sub

Private Sub Form_Open(Cancel As Integer)
    DoCmd.Close acForm, "0_STARTUP"

End Sub

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I don't see a question.

If the question is "how do I open on startup the last FORM accessed before the app was closed last time?" then --

You will need to add a new table (preferably in the BE) to log each Form as it opens.  You will also need to capture the username as he logs in.  You can't do anything with tables since tables do not offer any events and users should NEVER, EVER access tables or queries directly anyway.  As each form opens, it should update the record of a particular user in the log table to record that this user opened this form.  The code needs to be able to add a log record if one doesn't already exist for the user.  You can call this logging code from the Open event of each form.  You would pass in the name of the form.

Call MyLogger(Me.Name)

The reason I prefer the table to be in the BE rather the FE is because when you replace the FE to distribute updates, the table with the last Form for this user will be wiped out and replaced with the copy from your test FE.

Then instead of
    DoCmd.OpenForm "0_MasterDataFrm", acNormal
you would use
    DoCmd.OpenForm  Nz(DLookup("FormName", "tblLogUsage", "UserName = '" & loggedinusername & "'"), "0_MasterDataFrm"), acNormal

Creating a table every time the app opens sounds like you think you are working with a spreadsheet rather than with a relational database.

Also, rather than hardcoding the form name in expressions such as
DoCmd.Close acForm, "0_STARTUP"
Use a reference to the name of the current form
DoCmd.Close acForm, Me.Name

This is safer because
a) if you copy and paste the code, you won't have to remember to change the form name.
b) if you rename the form, the code won't break.  It will simply pick up the new form name.
c) if you create dummy forms that you copy whenever you create a new form so you don't have to keep redefining the wheel, the code references don't have to change each time.  I have several standard forms with headers/footers, font, color, standard buttons, standard procedures (open, close, BeforeUpdate) that include standard code snippets.
rogerdjrAuthor Commented:
The issue actually is that the last table or form that was open when I closed the database re-opens when I start-up.

I don't want this to happen.

Seems to be unique to this particular application - other databases I'm working don't do this?
There is an option to open the last used database when Access starts (Access Options/Client Settings/Advanced) but none to open the last used object that I have ever seen.

On the Access Options/Current Database sheet, you have the option to specify a startup form.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

rogerdjrAuthor Commented:
It seems to be something strange about this database

Please don't judge the content too harshly - I'm an amateur and I only use this as a working tool to learn and deliver results (reports) for clients

Is there a macro running?  Look for something named AutoExec.  Did you ever create a macro or attempt to write code to perform this automatic opening?

Try opening the database while holding down the shift key.  This stops the startup processes from running.
rogerdjrAuthor Commented:
The only thing I can think is if the spell check process I use on some objects might be an issue a typical example would be

Private Sub IDandDescripofInspStructures_Exit(Cancel As Integer)
    'Private Sub GeneralLocation_Exit(Cancel As Integer)
        On Error Resume Next

        If Nz(IDandDescripofInspStructures.Text, "") = "" Then
            Exit Sub
            IDandDescripofInspStructures.SelStart = 0
            IDandDescripofInspStructures.SelLength = Len(IDandDescripofInspStructures.Text)
            DoCmd.SetWarnings False
            DoCmd.RunCommand acCmdSpelling
            DoCmd.SetWarnings True
        End If
End Sub
You may have to post the database.  Please compact it and zip it first.
rogerdjrAuthor Commented:
See attached zipped database

I had some computer hardware issues that delayed my response
You seem to have disabled the shift-bypass key so I can't open the database and whatever code you have running is in a loop and so the database doesn't ever open.
rogerdjrAuthor Commented:
If I disabled the shift-bypass key it was not intentional - how would I re-enable it?
Can you open the database directly into design view by holding down the shift key?  If you can then there may be something wrong with the file you uploaded.  Please try compacting and zipping and upload again.
rogerdjrAuthor Commented:
it Opened fine in the design mode with shift key pressed

I compacted and re-zipped - see attached file

The last time i opened it the CASp_ImplementationPlan_SummaryDataTbl opened and access tried to spell check it. That was the last table I had opened when I was working on the database and closed it.

Very strange - I have several databases that I use as working tools (regularly adding tables, forms, reports, etc.) and none of them have this going on????
I can't actually get the form to load without errors because it references some files outside of the database. and since the files aren't found, I get errors.

There is a huge amount of code that runs when the form opens that makes opening the form extremely slow.  There are other ways to accomplish the filtering that don't require code.  For starters, you should be using the master/child links.  That keeps the subforms sync'd with the main form.  For the other queries, you can use criteria embedded in the query.  There is no need to rebuild the SQL string each time the form loads.

There is a lot of overhead associated with creating a new query that doesn't happen when you use querydefs.  Querydefs are "compiled" when they execute the first time and the execution plan that is calculated is saved for later use so subsequent executions of the query will use the saved plan rather than building a new one.  For your form, you are forcing Access to build quite a few execution plans before it can even open the form.

Also, when you replace a SQL string with a new one, Access automatically runs the query.  Your requeries are making the queries run twice which also adds to the slowness.

I never got to the point of trying to actually solve your problem and I don't really have any more time to look at this.  Sorry.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rogerdjrAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.