Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2002
    Location
    Illinois
    Posts
    133

    Change several forms' property with VBA

    I want to change one property on all of my forms - 50 of them. How do I do this with VBA? I tried the following without success:

    dim frm as form
    For each frm in Application.Forms
    frm.HasModule = False
    Next

    What's wrong with this code?

    Thanks,

    Steve
    SteveH

  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    From BOL
    The HasModule property can be set only in form or report Design view but can be read in any view.
    You'll have to add to your code to open each form in design view, and then set the HasModule property
    Inspiration Through Fermentation

  3. #3
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Something like this

    Code:
    Dim frm As Form, strFrm As String
    Dim frm2 As Form
    For Each frm In Application.Forms
    strFrm = frm.Name
    DoCmd.OpenForm strFrm, acDesign
    Set frm2 = Forms(strFrm)
    frm2.HasModule=false
    DoCmd.Close acForm, strFrm, acSaveYes
    
    Next
    Inspiration Through Fermentation

  4. #4
    Join Date
    Apr 2002
    Location
    Illinois
    Posts
    133
    Thanks you for the reply. I put this code in a sub within a module with no luck. I put a break on the For statement and found that frm = Nothing. Also found that the For Each...Next loop is never entered. It skips right to the Exit Sub line.
    SteveH

  5. #5
    Join Date
    Dec 2006
    Posts
    53
    The fact that the for each statement is never entered can only indicate that VBA does not see any frm (Forms) in Application.Forms. Don't know why . . .

  6. #6
    Join Date
    Apr 2002
    Location
    Illinois
    Posts
    133
    I got this reply on another forum. It worked for me. Thanks Doug!

    The Forms collection only contains those forms that are open, not all of
    them.

    Here's code that will list all forms:

    Dim dbCurr As Database
    Dim docLoop As Document

    Set dbCurr = CurrentDb()

    For Each docLoop In dbCurr.Containers!Forms.Documents
    Debug.Print " " & docLoop.Name
    Next docLoop

    Alternatively, in Access 2000 or newer, you can use:

    Dim objForm As AccessObject
    Dim objDatabase As Object

    Set objDatabase = Application.CurrentProject
    For Each objForm In objDatabase.AllForms
    Debug.Print objForm.Name
    Next objForm

    --
    Doug Steele, Microsoft Access MVP
    SteveH

  7. #7
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Quote Originally Posted by SteveH
    The Forms collection only contains those forms that are open, not all of
    them.
    heh... a minor technicality.

    Forgot about that. Sorry
    Inspiration Through Fermentation

Posting Permissions

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