Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    Form not found crash

    Because I am using

    http://allenbrowne.com/ser-35.html

    to open forms,

    When I have the code
    Code:
    If CurrentProject.AllForms("frmSchoolsFound").IsLoaded Then
    Forms!frmSchoolsFound!SchoolsBookingsListSub1.Requery
    End If 'ends the check to see if the report is open
    it crashes due to it not finding the form



    the form is loaded but it can't find the form because it is an instance - is there a work around?

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    What name did you give your object/ class?

    If said object does not recognize the requery method you will have to set object to = nothing and instantiate again.

  3. #3
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by ItsMe View Post
    What name did you give your object/ class?

    If said object does not recognize the requery method you will have to set object to = nothing and instantiate again.
    Not sure what you mean

    original code

    Code:
    Private Sub SchoolName_DblClick(Cancel As Integer)
      'Purpose:    Open an independent instance of form frmClient.
        Dim frm As Form
    
    
        'Open a new instance, show it, and set a caption.
        Set frm = New Form_frmSchoolsFound
        frm.Visible = True
        
        frm.Filter = "[NewSchoolsID] = " & [NewSchoolsID]
        frm.FilterOn = True
        frm.Caption = [SchoolName]
        'Append it to our collection.
        clnClient.Add Item:=frm, Key:=CStr(frm.hwnd)
    
    
        Set frm = Nothing
    End Sub
    
    Function CloseAllClients()
        'Purpose: Close all instances in the clnClient collection.
        'Note: Leaves the copy opened directly from database window/nav pane.
        Dim lngKt As Long
        Dim lngI As Long
    
    
        lngKt = clnClient.Count
        For lngI = 1 To lngKt
            clnClient.Remove 1
        Next
    
    
    
    
    End Function
    (The public variable is clnClient)


    The on form close event
    Code:
    Private Sub Form_Close()
        'Purpose: Remove this instance from clnClient collection.
        Dim obj As Object        'Object in clnClient
    
    
        Dim blnRemove As Boolean  'Flag to remove it.
    
    
        'Check if this instance is in the collection.
        For Each obj In clnClient
            If obj.hwnd = Me.hwnd Then
                blnRemove = True
                Exit For
            End If
        Next
    
    
        'Deassign the object and remove from collection.
        Set obj = Nothing
        If blnRemove Then
            clnClient.Remove CStr(Me.hwnd)
        End If
    End Sub

  4. #4
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    I am guessing clnClient is the object and shouldn't be treated as a form to requery?

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    This is just a guess because I do not create instances of forms. But OOP is OOP is OOP

    So frm is your object. In your code you instantiate it as a new instance of a named form object, "frmSchoolsFound". Then you set frm to = Nothing

    The problem, as I see it, is you do not close your new object before you set frm to = Nothing. Do not set frm to = Nothing until after you frm.Close. Also, instead of trying to use a fully qualified name for your object just use the shortcut, frm.Requery.

    Wherever you have your sub-procedure, "SchoolName_DblClick", do not close this until after frm.Close. Closing the class will abolish your instance. Closing the class that has the code for your sub-procedure, "SchoolName_DblClick" is the same as set frm = Nothing

  6. #6
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Even if I remove Set frm = Nothing I still get the error

    If I am closing the class using
    Function CloseAllClients()?

  7. #7
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Let's say you use Form1's module to write some code. You open Form1 and click a button. The button fires some code and creates an instance of another Form Object or even another instance of Form1. Now you close Form1 before using the .Close method on your new instance. As far as I can tell, you just lost control of that new instance. At least via VBA.

    What is it that you are trying to requery? The new instance of the form? Use frm.Requery

  8. #8
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    sorry ignore Function CloseAllClients()?

    I am not even using it

  9. #9
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by ItsMe View Post
    Let's say you use Form1's module to write some code. You open Form1 and click a button. The button fires some code and creates an instance of another Form Object or even another instance of Form1. Now you close Form1 before using the .Close method on your new instance. As far as I can tell, you just lost control of that new instance. At least via VBA.

    What is it that you are trying to requery? The new instance of the form? Use frm.Requery
    on the form there is a subform that lists bookings that needs be refreshed after viewing or changing the booking. I am only opening instances of the original form (and there is more than one open at a time).

    Perhaps put the requery (which is in a function) in the unload - that way before the form closes it fires off the unload, refreshes the form then....?

    wait that wont help either

    Note: I never open frmSchoolsFound - only the instance

  10. #10
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    If I make a public function

    Function closeInstance(varHWND As variant)


    'Purpose: Remove this instance from clnClient collection.
    Dim obj As Object 'Object in clnClient


    Dim blnRemove As Boolean 'Flag to remove it.


    'Check if this instance is in the collection.
    For Each obj In clnClient
    If obj.hwnd = varHWND Then
    blnRemove = True
    Exit For
    End If
    Next


    'Deassign the object and remove from collection.
    Set obj = Nothing
    If blnRemove Then
    clnClient.Remove CStr(varHWND )
    End If


    End Function

    Then will this work as I don't have it in the form's close event...

  11. #11
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    ignore my question above

    since I add an instance and put it in a collection using clnClient.Add Item:=frm, Key:=CStr(frm.Hwnd)

    can't I refer to the key and item and then use that to refer to it to be requeried?

  12. #12
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Not totaly understanding your collection. I would have to break it down. Not something I normaly work with. I will say this. You are going to need to know the handle of the form.

    So you will have to iterate the collection and find the correct .hwnd before you could adjust a property of the relative form within the collection.

    But who cares about the collection anyway? You are all over the place. You created an instance within (I guess) a form's module. If you want to evoke a method like .Requery, do it in the form's module. BEFORE YOU set frm = nothing

    frm.Requery

    end of story.

    There is nothing else to it. Creating a UDF in a Standard module does not make sense. You are making classes within classes and then going global to interact with a class via its handle?????

    Way more complex than it needs to be.

  13. #13
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by ItsMe View Post
    Not totaly understanding your collection. I would have to break it down. Not something I normaly work with. I will say this. You are going to need to know the handle of the form.

    So you will have to iterate the collection and find the correct .hwnd before you could adjust a property of the relative form within the collection.

    But who cares about the collection anyway? You are all over the place. You created an instance within (I guess) a form's module. If you want to evoke a method like .Requery, do it in the form's module. BEFORE YOU set frm = nothing

    frm.Requery

    end of story.

    There is nothing else to it. Creating a UDF in a Standard module does not make sense. You are making classes within classes and then going global to interact with a class via its handle?????

    Way more complex than it needs to be.
    I only open an instance - from that instance I open another different form (booking) and when I am finished with the booking form, I close that form (booking) which in turn before closing, looks for frmSchoolsFound and requeries it. Because I am dealing with an instance it then can't be found (because I have set it to nothing.)

    I only need the form to requery when the form booking closes (the instance is still open)

    If I knew how to refer to the instance then I would requery that.

  14. #14
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Form1 - search schools form

    Form2 - the instance (frmSchoolsFound)

    Form3 - Booking form (where I requery frmSchoolsFound before closing)

  15. #15
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You painted yourself into a corner. All I can think of at this point is to iterate the collection and use the handle of the form (window) to create another instance within VBA. With that you should be able to regain control. I seem to recall that the fully qualified name of duplicated forms follws a naming convention. Maybe you can google for that convention and see if you can get the correct name. It seems, Forms!frmSchoolsFound!SchoolsBookingsListSub1 is not the fully qualified name of the form you created.

    The other option is not to set frm = nothing

    So, instead of calling it frm. Call it something that is more unique. ofrmMyNewForm

    Declare ofrmMyNewForm as Form in the header of your first form

    In your first first form, create the form as usual but do not set ofrmMyNewForm nothing

    create another sub in your first form

    sub My_Obj_Requery

    ofrmMyNewForm.requery

    end sub

    Now all you have to do is use the fully qualified name of your first form, from frmBooking, to call the sub My_Obj_Requery. Right now I am not remembering the syntax to call a private procedure in a class. You may have to use a hidden control and use one of its events to call the sub.

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

Similar Threads

  1. Access crash
    By Tjaaaa in forum Access
    Replies: 10
    Last Post: 03-07-2014, 05:41 PM
  2. FindRecord Crash if criteria not found
    By quicova in forum Programming
    Replies: 4
    Last Post: 09-13-2013, 08:42 AM
  3. Replies: 3
    Last Post: 04-09-2013, 01:35 PM
  4. Replies: 1
    Last Post: 12-02-2010, 03:04 PM
  5. Form Crash
    By AKQTS in forum Forms
    Replies: 3
    Last Post: 10-21-2010, 10:02 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