Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing control properties in forms collection 2

Status
Not open for further replies.

galorin

MIS
Nov 22, 2007
154
GB
I want to globall change the font used in my application, but I don't know how to address the collection. My code would be something like

for each form in FormCollection
for each control in form
font = arial
next control
next form

but I don't know how to get at the collection of forms.
 
AllForms collection
Forms collection

Did you look these up in the helpfile? If you type in "forms collection" this clearly comes up. The vba helpfile is very thorough make it your friend.
 
Same thing with the object browser. Type in forms and Allforms and get familiar with the objects.
 
How are ya galorin . . .

Also, for permanent changes the forms have to be opened in design view!

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Bah, this is looking like, even with 55 forms to change, I'd be faster doing it by hand than coding it.
 
Well, I can now claim VICTORY!!!!!!!!!

Mostly. Here's my code.
Code:
Function changeFont(frmName As String)
Dim frm As Form
Dim i As Integer
Dim intCnt As Integer

 Set frm = Forms(frmName)
 intCnt = frm.Count
 For i = 0 To intCnt - 1
   Select Case frm(i).ControlType
    Case acLabel
     frm(i).FontName = "Arial"
    Case acCommandButton
     frm(i).FontName = "Arial"
    Case acTextBox
     frm(i).FontName = "Arial"
    Case acComboBox
     frm(i).FontName = "Arial"
    Case acListBox
     frm(i).FontName = "Arial"
   End Select
 Next i
End Function

and on the on_load() event, I put in this
Code:
Call changeFont(Me.Form.Name)

I hate Access.
Have I missed any control types that have a font property?
Did I mention that I hate Access?
 
Code:
Public Sub ModifyAllForms(fontName as string)
  On Error GoTo errlbl
  Dim elapsed As Single
  Dim frm As AccessObject
  Dim openFrm As Access.Form
  Dim cntrl As Access.Control
  Dim txtbx As Access.TextBox
  elapsed = Timer()
  For Each frm In CurrentProject.AllForms
    DoCmd.OpenForm frm.Name, acDesign
    Set openFrm = Forms(frm.Name)
    For Each cntrl In openFrm
      cntrl.FontName = fontName
    Next cntrl
    DoCmd.Save acForm, frm.Name
    DoCmd.Close acForm, frm.Name
  Next frm
  elapsed = Timer - elapsed
  MsgBox elapsed
  Exit Sub
errlbl:
  If Not Err.Number = 438 Then
    MsgBox Err.Number & " " & Err.Description
  End If
  Resume Next
End Sub
takes about a second to do Northwind.
 
There is a lot to be said for creating your own 'normal form'. It can be used in a number of ways, such as for autoformat and for ensuring continuity of style between forms and databases.
 
When I started this, I was given full reign as the lone developer, and decided on the visual style. As the project neared completion, we had a managerial re-shuffle, and I suddenly needed to present my app to a committee on a fortnightly basis. As a result of this re-shuffle, I have had to cut functionality in order to have a touchy-feely interface, as my release date is fixed. So I did have a fairly standardised interface, before the re-shuffle. I just needed a way to easily make aesthetic changes, which this thread has helped me to do. Many thanks all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top