Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    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
    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.

    fixed.

    I removed frm = nothing

    I placed a public variable (I could make an array/collection and search through - will do that later) then when the form opens event of frmSchoolsFound I put

    Code:
    lngHwnd = me.hwnd
    then in the function that requries any open forms I put

    Code:
    If CurrentProject.AllForms("frmSchoolsFound").IsLoaded Then
    
    
     For Each frm In Forms
     
     If frm.hwnd = lngHwnd Then
     frm.Requery
        Exit For
    
    else
    set frm = nothing  'added this line to set frm to nothing
    
     End If
     Next
    
    
    End If 'ends the check to see if the report is open
    really it can cause problems having hwnd save to only one variable value instead of an array/collection because there is more than one instance (if the user moves between forms, the variable will be udpated with the current open form and therefore only refresh that single one.

  2. #17
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    I could make it that if no frm in forms is available then set frm = nothing on a close event of the booking form


    I could also pull the hwnd from clnclient - knowing how to cycle through those would be helpful


    something like on the lines of...

    If frm.hwnd = clnClient.Key Then
    frm.Requery
    Exit For
    End If
    Next

    but I don't know

  3. #18
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Sorted

    Code:
    If CurrentProject.AllForms("frmSchoolsFound").IsLoaded Then
    
    
    
    
    Dim obj As Object
    For Each obj In clnClient
        ' Perform desired processing on each item.
    For Each frm In Forms
     If frm.hwnd = obj.hwnd Then
     frm.Requery
        Exit For
     End If
    
    
     Next
    Next
    
    
    Else
    Set frm = Nothing
    End If 'ends the check to see if the report is open
    Its me - I humbly thank you

    also not sure if that exit for stops loop for all open instances - but I was hoping you can tell me that.

  4. #19
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Also if I try to set frm = nothing and frm hasn't been created yet (due to a different form opening up the booking form) will my code crash or will VBA ignore it?

    I guess I could do an if with isnothing()

  5. #20
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    What I see the code in post#18 doing is refreshing each form.

    The reason I mention to not
    set frm = nothing
    is so you do not abolish your instance of the form. Yes, your form is still open. That is because you never closed it using frm.close.

    I should have thought of this last night. I was stuck on keeping the instance open and using it to refresh the form. What you can do is declare an integer that is available globally, like gintNewFrmHandle

    In your original code that creates the instance use the following
    Set frm = New Form_frmSchoolsFound
    frm.Visible = True
    gintNewFrmHandle = frm.hwnd

    Then you can use this global variable in another form's module. Something like...


    Code:
    dim frm as forms
    For Each frm In Forms
    If frm.hwnd = gintNewFrmHandle Then
    frm.Requery
        Exit For
    End If
    Next
    That should do it. It is a similar approach to your UDF in post #10. Only this way you have a global variable that is designated for THAT SPECIFIC form and you iterate the collection without a UDF that you pass the handle to.

  6. #21
    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 I see the code in post#18 doing is refreshing each form.

    The reason I mention to not
    set frm = nothing
    is so you do not abolish your instance of the form. Yes, your form is still open. That is because you never closed it using frm.close.

    I should have thought of this last night. I was stuck on keeping the instance open and using it to refresh the form. What you can do is declare an integer that is available globally, like gintNewFrmHandle

    In your original code that creates the instance use the following
    Set frm = New Form_frmSchoolsFound
    frm.Visible = True
    gintNewFrmHandle = frm.hwnd

    Then you can use this global variable in another form's module. Something like...


    Code:
    dim frm as forms
    For Each frm In Forms
    If frm.hwnd = gintNewFrmHandle Then
    frm.Requery
        Exit For
    End If
    Next
    That should do it. It is a similar approach to your UDF in post #10. Only this way you have a global variable that is designated for THAT SPECIFIC form and you iterate the collection without a UDF that you pass the handle to.

    Sort of understand you - but then wouldn't that global variable gintNewFrmHandle only have the one hwnd number? Every time I create an instance each instance has their own hwnd number - the problem I would see is if a user first opened the form, then switched back to the search form and opened another, then the variable would have the hwnd number of form 2 and not form one - a problem if you open another form from Form1 and try to refresh form1 and you end up refreshing instance form2

    That is why I used the collection again since it is already publicly declared and storing all the hwnd's as keys - I can refer to any one if I need to... I think...

    I do want to abolish it in the end but only if no form is open (which is the code later) however if it causes conflicts again just because another form could open the third booking form then I have a problem when it tries to abolish frm that does not exist....

    Also is a collection a hash and not an array?

  7. #22
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by Ruegen View Post
    ...already publicly declared and storing all the hwnd's as keys - I can refer to any one if I need to... I think...

    ..
    If you can that is good. That is what you need. I was real tired last night trying to make sense of some complex code.

    Yes, you need to know the handle if the orignal instance in VBA is not longer available.

    For instance, the function you posted to close the instance requires you to pass the handle as an argument. If you have a way of knowing the handle via a key, great. If the key is a string array that represents the collection that will work, for the entire collection. Just need to understand how to use your key.

  8. #23
    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
    If you can that is good. That is what you need. I was real tired last night trying to make sense of some complex code.
    That and trying to decipher my ramblings

    Thanking you again ItsMe I feel less like I'm winging it when I get your advice

Page 2 of 2 FirstFirst 12
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