DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  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

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links