Results 1 to 7 of 7
  1. #1
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936

    Sequence of events opening a database


    I have a subform (single) with an OnLoad event of go to new record. When I open the database the form opens but gives me the error "2046 You can't go to the specified record". If I open the form from the nav pane it opens without the error. What gives?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    make a macro called AUTOEXEC
    in the 1st line, use OPENFORM
    set the DATAMODE = ADD

    it will open to add records.

  3. #3
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Didn't work - maybe because it is a subform, not the form that is being opened?

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    subforms open before the mainform so if you have code referring to the mainform or its recordset in your subform opening events (open, load, current), recordsource or list/combo rowsources it won't find it.

    If you have multiple subforms (say 5) the first one to open will have its current event triggered 5 times, the second to open 4 times etc. The main form is the last form to open.

    You say your load event is to go to new record. If the subform control on the mainform has the linkchild/linkmaster properties set, then this cannot work because at that point the linkmaster property will not have been assigned - and the subform needs it to populate the designated linkchild field. When opened as its own form, there is no parent form, so not an issue.

    See this link or google 'access order of events'

    https://support.office.com/en-us/art...ad=US&fromAR=1

    and find the section working with subforms

    Take a look at this link for an example solution

    http://stackoverflow.com/questions/1...k-on-a-subform

  5. #5
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Lots of rules I have broken! 2 subforms, so it gets triggered twice. Link properties, so not yet populated.

    I still don't get why there is no error when the main form is opened from the nav pane, however.

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    They are not really rules
    Lots of rules I have broken! 2 subforms, so it gets triggered twice.
    It doesn't matter except there will be a performance hit if there is code in the subform current event - for example to populate a combo rowsource or format controls.

    Link properties, so not yet populated.
    again, doesn't matter if there is no code in the open/load events that rely on the linkmaster property being populated

    as a test, put something like this in each event

    debug.print "subformcontrolname_open event" (change names to suit)

    To see how many times they are triggered, open the form and see the order of events and frequency they occur. Can be a good way to improve performance of the form. I tend to set subform recordsources to something like 'SELECT .... WHERE False" so data isn't loaded and then in the mainform current event I have code to change it to say "....WHERE FK=" & me.PK.

    I still don't get why there is no error when the main form is opened from the nav pane, however.
    I read this

    If I open the form from the nav pane
    to mean opening the subform

  7. #7
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Sorry for the unclear post! Thanks for all that good advice, I will try and change some things tomorrow.

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

Similar Threads

  1. Creating an "Events Database" -- Is my structure Correct?
    By KingOf206 in forum Database Design
    Replies: 14
    Last Post: 10-07-2015, 09:35 PM
  2. Database not opening
    By jj1 in forum Access
    Replies: 6
    Last Post: 08-18-2014, 09:15 PM
  3. Replies: 2
    Last Post: 07-30-2014, 08:03 AM
  4. Replies: 3
    Last Post: 05-23-2013, 05:30 PM
  5. Database Relations between Names and Events
    By flebber in forum Database Design
    Replies: 6
    Last Post: 11-22-2011, 02:01 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