If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Change several forms' property with VBA

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
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
Reply With Quote
  #2 (permalink)  
Old
Village Idiot
 
Join Date: Jul 2003
Location: Michigan
Posts: 1,941
From BOL
Quote:
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
Reply With Quote
  #3 (permalink)  
Old
Village Idiot
 
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
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
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
Reply With Quote
  #5 (permalink)  
Old
Registered User
 
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 . . .
Reply With Quote
  #6 (permalink)  
Old
Registered User
 
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
Reply With Quote
  #7 (permalink)  
Old
Village Idiot
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On