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

    Creating new object of form stay hidden first

    I launch duplicates of forms using



    Dim frm As Form


    'Open a new instance, show it, and set a caption.
    Set frm = New Form_frmSchoolsFound
    frm.Visible = false

    however I want the form to be hidden on launch rather than popping up and then becoming visible to false - even if I have it to false it launches first, then dissapears from view. I would like to keep it hidden first then do all this stuff to it like filter then eventually put it's visibility to true.

    any suggestions?

  2. #2
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Why not launch it when you actually need it? Is it a Popup form?

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

    The form opens up from a list of school, because I want more than one window open of the same form for different schools I make instances of each form then filter them to match the same school as the one selected from the list.

    However the filtering process shows the other records first before it refreshes with the filter.

  4. #4
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Your answer is unclear to me. Please explain in steps, which form, frm1, frm 2 . What other records, on what form? Filtering from a combo, code ?

  5. #5
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    frmSchoolsFound is the regular form

    I create an object frm as form
    then I set frm = new form_frmSchoolsFound

    this way I make a function that opens the frmSchoolsFound to many records at the same time instead of one.

    say I have a list box of schools, each one I click it opens up an new form of "frmschoolsfound" and filters it to match the selected school from the listbox

  6. #6
    hansendl is offline Advanced Hobbyist
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    38
    Try running the code without the line "frm.Visible = False". By default, I believe forms instantiated in code are not visible until you explicitly make them visible. I create dialog forms like this frequently in code where I instantiate the form, set a bunch of properties, then make it visible by setting frm.Visible = True. Until I actually run that line of code, the form is loaded, but remains invisible.

    Example:
    Code:
    Private WithEvents dlg As Form_frmOrgPickDialog
    
    Private Sub SelectOrg(cbo As Access.ComboBox) 
    Set dlg = New Form_frmOrgPickDialog
    With dlg
    .ExpansionLevel = 2
    .DisplayOrgType = otSelect
    .BuildTree
    If Not IsNull(cbo) Then
    .ActiveNode = "o" & cbo.Value
    End If
    End With
    dlg.Visible = True
    
    
    End Sub

  7. #7
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Sounds like that could be easily done with a Main form/Subform using a Combo but, that's just me. You do this because you NEED to work on many forms at the same time?
    I really can't visualize your situation, sorry. Maybe someone else can.

  8. #8
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by burrina View Post
    Sounds like that could be easily done with a Main form/Subform using a Combo but, that's just me. You do this because you NEED to work on many forms at the same time?
    I really can't visualize your situation, sorry. Maybe someone else can.
    yeah the staff might be looking at two schools using the same form and they don't want to close the form to view another school. (especially when they have a call from a school while they are working with another record)

    each form shows details like booking details, address, history, memo etc.

  9. #9
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    You know your needs better than me. But I would visualize a Tabbed form approach myself filtered by area (Whatever it's called in the UK) . Just my 2 cents.

    Did hansendl 's approach work for you?

  10. #10
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by hansendl View Post
    Try running the code without the line "frm.Visible = False". By default, I believe forms instantiated in code are not visible until you explicitly make them visible. I create dialog forms like this frequently in code where I instantiate the form, set a bunch of properties, then make it visible by setting frm.Visible = True. Until I actually run that line of code, the form is loaded, but remains invisible.

    Example:
    Code:
    Private WithEvents dlg As Form_frmOrgPickDialog
    
    Private Sub SelectOrg(cbo As Access.ComboBox) 
    Set dlg = New Form_frmOrgPickDialog
    
    With dlg
    .ExpansionLevel = 2
    .DisplayOrgType = otSelect
    .BuildTree
    If Not IsNull(cbo) Then
    .ActiveNode = "o" & cbo.Value
    End If
    End With
    dlg.Visible = True
    
    
    End Sub
    yeah it still does it (flick from unfiltered to filtered)

    my code
    Code:
          'Open a new instance, show it, and set a caption.    
    Dim frm As Form
    Set frm = New Form_frmSchoolsFound
        
        Dim strNewSQL As String
        Dim qdf As DAO.QueryDef
        Set qdf = CurrentDb.QueryDefs(frm.RecordSource)
        
        strNewSQL = qdf.SQL
        Set qdf = Nothing
        
        strNewSQL = Replace(strNewSQL, "WHERE " & Chr(40) & Chr(40) & Chr(40) & "tblSchools.Removed" & Chr(41) & " Is Null" & Chr(41) & Chr(41), "")
        
        With frm
            .RecordSource = strNewSQL
            .Filter = strWhere
            
            .FilterOn = True
            .Caption = IIf(IsNothing(frm.Form!SchoolName), "no name", frm.Form!SchoolName) '"Schools Found" &
        End With
          
            If cycleFoundSchools(frm.Form!NewSchoolsID) Then
            MsgBox "School " & IIf(IsNothing(frm.Form!SchoolName), "no name", frm.Form!SchoolName) & "  is already open, the opening form will close."
            Else
            'Append it to our collection.
            clnClient.Add Item:=frm, Key:=CStr(frm.Hwnd)
            End If
            
        frm.Visible = True
        Set frm = Nothing
    note updated for easier viewing

  11. #11
    hansendl is offline Advanced Hobbyist
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    38
    My mistake...in stepping through my code I see now that the form becomes visible as soon as I run the Set statement. I had assumed that the form was not visible until I explicitly made it visible, but that is clearly not the case.

    How about running a DoCmd.OpenForm method, setting the WindowMode argument to AcHidden, then setting your frm variable equal to the open form (Set frm = Forms("frmSchoolsFound")? For multiple instances, you may need to use the hWnd property to be sure you're pointing your frm variable to the correct "frmSchoolsFound" instance (since they will all have the same name), but that should be easy enough to handle through code.

    r/
    Dean

  12. #12
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by hansendl View Post
    My mistake...in stepping through my code I see now that the form becomes visible as soon as I run the Set statement. I had assumed that the form was not visible until I explicitly made it visible, but that is clearly not the case.

    How about running a DoCmd.OpenForm method, setting the WindowMode argument to AcHidden, then setting your frm variable equal to the open form (Set frm = Forms("frmSchoolsFound")? For multiple instances, you may need to use the hWnd property to be sure you're pointing your frm variable to the correct "frmSchoolsFound" instance (since they will all have the same name), but that should be easy enough to handle through code.

    r/
    Dean
    Yes, it just happens so quickly that you don't notice it is not set to visible (not in my case because it does a few checks first which slows it down).

    I guess I could open the form, store it's hwnd, then make an instance of that and filter the instance then make it visible. It's not a bad suggestion but I will have to make sure no other buttons open that form without an instance creation (just opening the form generally) which I think I have in one spot. Since I travel to Europe this week that is something I probably won't tackle until I get back less I have a bunch of angry staff if something goes wrong...

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

Similar Threads

  1. Replies: 1
    Last Post: 05-07-2012, 06:41 AM
  2. Refilter form and stay on same record
    By ny1994rangers in forum Forms
    Replies: 1
    Last Post: 04-17-2012, 12:04 PM
  3. form won't stay in restored down size
    By markjkubicki in forum Forms
    Replies: 4
    Last Post: 08-15-2011, 07:46 AM
  4. Replies: 0
    Last Post: 01-18-2011, 07:09 AM
  5. Replies: 3
    Last Post: 09-16-2010, 09:50 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