Results 1 to 3 of 3

Thread: For Each and Forms

  1. #1
    Guest

    Question

    Hello all,

    I know that it is possible to go through every control on a form, like this:

    Dim objControl As Control
    Dim intCounter As Integer

    For Each objControl in Form1.Controls
    objControls.Caption = "Control" & intCounter
    inCounter = intCounter + 1
    Next


    What about going through the Forms in a project?

    This doesn't work though:

    Dim aform As Form
    For Each aform In ProjectName
    If aform.Name <> "Form1" Then
    aform.Enabled = False
    End If
    Next


    Is there a way to go through forms in a project like going through controls on a form?

    Thanks

    Sunny L.

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'address all forms in a project
    
    Public Sub UnloadAllForms()
    	Dim Form As Form
       		For Each Form In Forms
          			Unload Form
          		Set Form = Nothing
       	Next Form
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Guest
    This will make all Forms (except Form1) invisible.

    Code:
    Dim Frm As Form
    
    For Each Frm In Forms
        'If the Name is not Form1 then make it invisible
        If Frm.Name <> "Form1" Then Frm.Visible = False
    Next Frm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width