Results 1 to 9 of 9
  1. #1
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114

    Error 2455; Is Form view => Design view the same as Form view= close?

    The following code line is giving Error 2455, " You entered an expression that has an invalid reference to the property/form report."

    Code:
    If Not IsNull(Me!sbfShotList.Form.ShotNumber) Then
    This is a line from a main form Unload event, where sbfShotList is a subform control on the main form.

    But here's the thing: The error only happens when I click on design view while form is open. It executes normally when simply closing the form.



    What am I missing? Since the forms' (main & sub) unload events are triggered when I go from form view to design view, I've been assuming all along that that's a valid way to be testing my VBA routines. Is this not so? What's the difference between going from form view to design view vs. closing the form while in form view? The subform is in datasheet view, in case that's relevant. I also tried compacting the db, with no improvement.

    Thx for any help, Ron

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    I have never used the Unload event. Why should this code run when the form unloads? What is the remainder of the code?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114
    It's an adaptation of this technique:http://allenbrowne.com/ser-18.html designed to open a form to the same record it was on when the previous session was closed. (The OnLoad event reads the information stored here.) I used it while developing the subform as an independent form, and it worked fine. The codeblock from which I extracted the above line is (without the DIM statement):

    Code:
     If Not IsNull(Me!sbfShotList!Form.ShotNumber) Then
            Set rs = CurrentDb().OpenRecordset("tblInterSessionPlacemark", dbOpenDynaset)
            With rs
                .FindFirst "[fldVariable] = 'ShotIDLast'"
                If .NoMatch Then
                    .AddNew        'Create the entry if not found.
                        ![fldVariable] = "ShotIDLast"
                        ![fldvalue] = Me!sbfShotList.Form.ShotNumber & Me!sbfShotList.Form.ShotNumSuffix
                        ![fldDescription] = "Last Shotnumber for form " & Me!sbfShotList.Form.Name
                Else
                    .Edit          'Save the current record's primary key.
                        ![fldvalue] = Me!sbfShotList.Form.ShotNumber & Me!sbfShotList.Form.ShotNumSuffix
                    .Update
                End If
            End With
            rs.Close
        End If
        Set rs = Nothing
    This is an adaptation of what I had in the subform originally, with object references changed to refer to the form now as a subform. The reason this has to now be in the main form is the main form closes before the subform. (I learned the hard way that this is not the symmetrical reverse of when they open, whence the subform opens first )

    As mentioned, the above code works when run. It only draws the error when moving from form view to design view. I've now found various references over the years where people report issues with this error. Their situations seem similar to mine - many happening where subform controls are referenced from a main form event - though no evident cause or solution. One person suggested it has something to do with the timing of the closings, that maybe the subform objects are destroyed earlier than when the main form unload fires, and that one should simply trap the error and move on. I was hoping someone here may have a more concrete explanation/solution.

    Thanks for any help, Ron

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    I still don't understand why you want this code in Unload event as opposed to Close or a command button Click event (I always disable the X close and use command buttons to close form).
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114
    Well I put it in Unload because that's where Allen Browne said to put it. I just tried it in the Close event, with the same error. Not surprising, since Close occurs after Unload, and if the error has something to do with the subform control going out of scope before it's "supposed" to ie. - before the main form Unload fires - then it's a cinch the problem will be there later in the chain.

    Incidentally, today I'm getting error 2265 when trying to close out normally. (A real puzzlement, since it was not the case yesterday.) I've had to comment out the above block to avoid a debugging loop trying to close the form. (How do you do a break on the debugger and go directly to design view? It takes me forever to get out of that loop, and then I can't remember how I did it.) Anyway, that error also seems to point to the subform being out of scope before it's supposed to be. BTW, the subform's own unload event has nothing in it except a message box. I've also recompiled with no help.

    What I'm really asking is: 1.) Does anyone see why this code should cause this problem? 2.) Has anyone else experienced it and if so, how did you deal with it?

    Thx, Ron

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    Never had to deal with it because I never used the Unload event and seldom use Close event (actually only used on reports). Sorry I don't have more info and that no one else has jumped in.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114
    Quote Originally Posted by June7 View Post
    Never had to deal with it because I never used the Unload event and seldom use Close event (actually only used on reports). Sorry I don't have more info and that no one else has jumped in.
    Thanks June. I just discovered that the code does run without error if I put it in the main form's subform control (not the subform itself) On Exit event, so I can accomplish what I want. But more and more it looks to me like an issue relating to just when that control goes out of scope. Would still appreciate insight from anyone intimate with the sequencing of these events.

    This: http://office.microsoft.com/en-us/ac...005186761.aspx is what I've been referring to on the sequence, and perhaps I've just been misinterpreting it, particularly the section labeled "Working with subforms "

    -Ron

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    I looked at that too but didn't clarify the issue about switching to design view you encountered. But glad you found a solution.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114
    Quote Originally Posted by RonL View Post
    ----------This: http://office.microsoft.com/en-us/ac...005186761.aspx is what I've been referring to on the sequence, and perhaps I've just been misinterpreting it, particularly the section labeled "Working with subforms "

    -Ron
    Thought I'd bump my own thread just to mention a trick I found posted somewhere that might help future novice searchers. (I'm sure the pros already know this.) For a main form/subform situation, if you leave blank the SourceObject property for the subform control in design view, but set it in the OnLoad event for the main form, then the main form will load before the subform. This is a way to subvert the usual event sequence (as described in the quoted reference). So, for example, an unbound control in the main form, whose value is used to filter the subform, is available as soon as the subform loads. (A disadvantage, of course, is you can't open the subform for editing in design view of the main form, because all that's there is an empty subform control. )

    -Ron

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

Similar Threads

  1. Cannot view all records in form view
    By thar2hag in forum Forms
    Replies: 1
    Last Post: 11-01-2012, 08:43 AM
  2. Replies: 16
    Last Post: 09-12-2012, 08:39 AM
  3. Unable to view query in design view
    By vemi007 in forum Queries
    Replies: 7
    Last Post: 01-19-2012, 11:36 AM
  4. Replies: 5
    Last Post: 12-22-2011, 01:12 PM
  5. Replies: 1
    Last Post: 10-24-2010, 11:32 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