Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    828

    Run time error on close form

    ProfileNew - Copy.zip

    Hi all,
    I am getting a run time error 2450 when i close my primary form "frmBusiness" and I cannot for the life of me figure this out.
    I made some changes to my form and now it says it cant find it on close? I have attached db, it opens to the frmBusiness, and if
    you just close it, the error arises its nasty head. I am not sure what I have done as I this has always worked well but with redesigning


    and such something has triggered it? I took out a lot of stuff so ruff as is but what is there works well except for the error.
    I would appreciate some assistance on this as I have no clue. All spelling is correct and no compile errors either.
    I just don't know.
    Thanks
    Dave

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    before the close statement put:
    ON ERROR RESUME NEXT
    docmd.close acform, "fMyForm"

    no error will show.

  3. #3
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    828
    Hi ranman256
    I tried this but still received error

    Code:
    Private Sub CmdClose_Click()
    On Error Resume Next
    DoCmd.Close acForm, "frmBusiness"
    End Sub

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,552
    Could just use Me.Name ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,421
    I'm going to let you discover the problem by way of teaching a method of troubleshooting. I could just tell you what to do, but you need to expand your troubleshooting capabilities.
    Go to editor, enable break on all errors then close your form. Keeping in mind that you just closed the form, the problem should be obvious.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    828
    It has something to do with the subform "sfrmBusinessAddress" but I just cant find it?

  7. #7
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    828
    Hi Micron,
    I put the break in and still dont get what the issue is. If I don't use break, then debug goes to With Forms!frmBusiness and if you hover over the following it is a Null but if I put a break in
    then hover over the following then it give me what is actual in the fileds.
    I am totally assuming right now that this is something to do with the With Forms ! frmBusiness needing to reference maybe the subform in some way as the error points to my subform code.
    Why it cant find that form is beyond me? The form is there, was open till i closed it... once closed it is evidently seeking for the form it wants and that baffles me.

  8. #8
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,421
    Yes it does. Try again and when it opens code to debug, type in immediate window
    ?currentproject.AllForms("frmBusiness").isloaded and hit enter. What does that tell you about the problem?

    After that, here's a couple of more things to help you with learning troubleshooting. Since you have no close event in the main form, add one with one line
    Msgbox "closing"
    just so you don't have an empty sub which can cause other problems that wouldn't apply here, but why is outside of the scope of this issue. Let's just say, avoid the practice.
    Put a breakpoint at End Sub. Close your form, click ok to msg and when code breaks on End Sub, F8 (certainly you know of that by now). Watch how the code flows.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,421
    Out posts crossed so I'll wait until you try the immediate window thing.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    828
    Quote Originally Posted by Micron View Post
    Yes it does. Try again and when it opens code to debug, type in immediate window
    ?currentproject.AllForms("frmBusiness").isloaded and hit enter. What does that tell you about the problem?
    So that tells me that it is False which it should be as I just closed it. Why would it be open if I just closed it?
    If I tab over to my other tab "Team Members" and close it is just fine, no error. So this tells me its in that
    sfrmAddress but why is it still seeking that form to be open?

  11. #11
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,421
    Why would it be open if I just closed it?
    The real question is, why would you be trying to reference it when it is closed?

    Private Sub UpdateTempAddress()

    With Forms!frmBusiness


    EDIT
    why is it still seeking that form to be open?
    Hopefully my question answers that? Good job on the TS - hope it helps you going forward. The answers to those questions were right in front of you, no? The error would even break at that line while you're stepping thru, so kind surprised you didn't spot it. Hope all this adds to your ts arsenal.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  12. #12
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    828
    OK,
    I took some classes & video lessons and this was the way it showed me to do it. I have not had any trouble till i made this a subform on my form. I had it previously in a subform and had no issues with it.
    This Private Sub UpdateTempAddress() updates my address box to the right and populates it. If I take that out, then it doesnt work at all. I guess my question is why when I made this a subform did it stop working
    and create an error. The only thing I am doing different from before is i made this an actual subform. On some other work, I had it as part of a subform and it worked. I just didnt like the way it was. I guess I dont
    understand how to stop it from doing this.

  13. #13
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    828
    I think i know what the issue is now, what a day! In any event, I put this on a tab in a subform so the tab is not directly attached to the primary form.
    If I put this subform directly on my form via subform and object, then it doenst effect it. If I use the tab as is, then i get error. Is there a way to do this on my tab like it is now?
    There should be a way to do this but not real sure, but i will play with it and see if i can get it to work!
    Thanks a lot
    Dave

  14. #14
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    828
    So, is there a way that I can still use like it is so that it is not seeking to find this form? I can put Call CmdTeamMembers_Click in my close button code but I dont think that is correct method at all.
    How do i get this to reference this so when I close the form it closes this also? Maybe some If statement that if form is open, then....??? I dont know
    Thanks
    Dave

  15. #15
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,421
    The only thing I am doing different from before is
    I'm here to tell you that THAT is rarely true.
    I don't understand your db but have to wonder why you use the Current event for this. It fires every time a record gets the focus (i.e. becomes the active record), or the form is requeried or refreshed. It also fires when a form is opened (but that would be a consequence of loading the records, thus querying the form and I just covered that). The tab control is of no consequence in this except to say it matters where you put it IF it contains a subform. Knowing the order of events is crucial to understanding your problem. Here it clearly states that the subform is unloaded after the main form closes. When it has closed, you are referring to it in subform code that ideally should not run, but it does run because a subform record becomes the active record because that form gets the focus so that it can do what it needs to do in the closing process.

    Sometimes the only answer is to handle raised errors but this is not one of them. The best approach is usually to prevent them in the first place. I have to believe some other event would be better for your sub call. Why not form BeforeUpdate and/or BeforeInsert and call it once rather than umpteen times as you are doing? I cannot say either of those are correct for your situation - depends on factors I don't understand re your application, but I would not do what you're doing.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 07-19-2016, 05:28 PM
  2. Replies: 2
    Last Post: 09-23-2015, 09:02 PM
  3. Replies: 6
    Last Post: 08-15-2015, 11:54 AM
  4. Replies: 0
    Last Post: 11-29-2011, 01:06 PM
  5. Access Form- Save/Close Button error
    By Ashe in forum Forms
    Replies: 3
    Last Post: 02-10-2011, 01:01 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