What's wrong with my code?????


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: What's wrong with my code?????

  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    What's wrong with my code?????

    [Originally posted by Bernie Kozlowski]

    This code for some reason does not cycyle through all open forms. If I have more than 4 forms open, it always only closes three. Less than 4 forms open it always leaves the form I want open, plus one other.

    Any Ideas???

    Sub closeforms()
    Dim frm As Form

    If gpurpose = "Enter" Then
    If frm.Name <> &quot;frm_Main_entry_form&quot; Then
    For Each frm In Forms
    DoCmd.Close acForm, frm.Name
    Set frm = Nothing
    Next
    End If
    Else
    If gpurpose = &quot;Edit&quot; Then
    For Each frm In Forms
    If frm.Name <> &quot;frm_Main_edit_form&quot; Then
    DoCmd.Close acForm, frm.Name
    Set frm = Nothing
    End If
    Next
    Else
    For Each frm In Forms
    If frm.Name <> &quot;frm_Main_view_form&quot; Then
    DoCmd.Close acForm, frm.Name
    Set frm = Nothing
    End If
    Next frm
    &nbsp; End If
    End If



    End Sub

  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    Re:What's wrong with my code?????

    [Originally posted by Greg DeBacker]

    It would seem that everytime you close a form it is resetting the Forms collection to the new number of forms. The For Each loop is getting out of sync. I really haven't tested this idea. It is just a thought.

    Grex

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center