Page 1 of 3 123 LastLast
Results 1 to 15 of 32
  1. #1
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10

    Unanswered: Apply property change to all forms

    Just a quickie:

    I want to set the same property to every form in my db:
    Example: I want to set the caption of every form to be "Test"

    Any way of doing this through VBA?
    George
    Home | Blog

  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Have a look at the Forms collection.
    ...
    For each Form in Currentdb.Forms
    ...
    Inspiration Through Fermentation

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    CurrentDb, that's what I was missing!
    Told you it was a quickie
    Cheers RNG
    George
    Home | Blog

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Actually, perhaps not....

    "Compile error: Method or data member not found"
    Code:
    For Each Form In CurrentDb.Forms
        Form.BorderStyle = 1
        Form.ControlBox = False
        Form.AutoCenter = True
        Form.AutoResize = True
        Form.MinMaxButtons = 0
        Form.CloseButton = False
        Form.Caption = Form.Caption & " ~"
    Next Form
    George
    Home | Blog

  5. #5
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    oops... I forgot, the Forms collection differs from the other collections.
    It only refers to the open forms. This was a topic not long ago, though, and someone posted a solution.
    Inspiration Through Fermentation

  6. #6
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    How about this:

    (from the help file)

    Sub AllForms()
    Dim obj As AccessObject, dbs As Object
    Set dbs = Application.CurrentProject
    ' Search for open AccessObject objects in AllForms collection.
    For Each obj In dbs.AllForms
    ...
    Inspiration Through Fermentation

  7. #7
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Search is being a *ahem* ache again...
    Code:
    Dim obj As AccessObject, dbs As Object
    Set dbs = Application.CurrentProject
    For Each obj In dbs.AllForms
            'Debug.Print Chr(9) & obj.Name
            'Set ActiveForm = obj
            Form.BorderStyle = 0
            Form.ControlBox = False
            Form.AutoCenter = True
            Form.AutoResize = True
            Form.MinMaxButtons = 0
            Form.CloseButton = True
            Form.Caption = Form.Caption & " ~"
    Next
    Quote Originally Posted by Error Message
    The runtime error is '2448-You can't assign a value to this object'
    Possible causes are that the control is on a read only form or the value is too big where neither is the case...
    George
    Home | Blog

  8. #8
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    You need to open the forms in design mode, change the properties and close & save
    Testimonial:
    pootle flump
    ur codings are working excelent.

  9. #9
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Since your are using
    For Each obj In Dbs.AllForms

    Shouldn't you be using
    obj.Borderstyle

    instead of
    Form.Borderstyle?
    Inspiration Through Fermentation

  10. #10
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    But I have 90 forms
    I wanted a clever way of doing it
    George
    Home | Blog

  11. #11
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    I thought that too RNG, but it doesn't like that any more - if I have Form. then when in debugging mode and you hold your mouse over it... it shows you te current property value - it doesn't with obj. which suggested to me that was wrong

    *scratches head*
    George
    Home | Blog

  12. #12
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by georgev
    But I have 90 forms
    I wanted a clever way of doing it
    programmatically....

    DoCmd.OpenForm "MyForm", acDesign

    DoCmd.Close acForm, "MyForm", acSave

    (or something like that).
    Testimonial:
    pootle flump
    ur codings are working excelent.

  13. #13
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    BTW - if I were doing this I would create a function\ class\ table (whatever) and put all these property values in that. Then paste some code into the load event of all your forms setting their property values from the values you put in your function\ class\ table.

    1) simple to do
    2) simple to change any property any time
    3) users can even choose their own look for their db
    Testimonial:
    pootle flump
    ur codings are working excelent.

  14. #14
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    This is based on the first ever thread I posted on dbf.

    Tidied up. It does most of what you are trying to do. I might pop it on the bank if I get time....

    Anyway - retrospectively add\ alter code modules for all the form in your db. Altering other properties is a pretty simple alteration:

    Code:
    Option Compare Database
    Option Explicit
     
    Public Sub AddAlterFrmMdl()
     
    Dim i As Integer
    Dim save_flag As AcCloseSave
    Dim open_call As String
    Dim close_call As String
    Dim frm As Form
    Dim op_ret As Long
    Dim cl_ret As Long
    Dim st_line As Long
    Dim end_line As Long
    Dim st_col As Long
    Dim end_col As Long
     
    '################################################################################
    'This code puts in the open and close logging for forms
     
    'Code we want to insert in the open and close procedures.
    open_call = "'Call OpenFunction (Me.Name)"
    close_call = "'Call CloseFunction(Me.Name, 2)"
     
    'Loop through the forms container
    For i = 0 To Application.CurrentDb.Containers("Forms").Documents.Count - 1
     
    'Open each form in design mode
        DoCmd.OpenForm Application.CurrentDb.Containers("Forms").Documents(i).Name, acDesign
     
    'clear the save flag
        save_flag = acSaveNo
     
    'instantiate our form object
        Set frm = Forms(Application.CurrentDb.Containers("Forms").Documents(i).Name)
     
        With frm
     
    'Add a module if does not have one
     
            If .HasModule = False Then
                .HasModule = True
                save_flag = acSaveYes
            End If
     
            With .Module
     
    'Look for the code.
    'Note the st_line, st_col, end_line, end_col variables. These are passed ByRef so a return
    'value comes back for us to use below.
                If .Find(open_call, st_line, st_col, end_line, end_col, True, True) = False Then
     
    'If not there then check if there is an on open event procedure
                    If .Find("Form_Open", st_line, st_col, end_line, end_col, True, True) = True Then
     
    'Add the lines if there is.
                        .InsertLines st_line + 1, vbCrLf & vbTab & open_call
     
                    Else
     
    'Create the event and add the lines if not.
                        op_ret = .CreateEventProc("Open", "Form")
                        .InsertLines op_ret + 1, vbCrLf & vbTab & open_call
     
                    End If
     
    'set the save flag
                    save_flag = acSaveYes
     
                End If
     
    'Clear the positioning variables
                st_line = 0
                st_col = 0
                end_line = 0
                end_col = 0
     
    'Repeat for the close event.
                If .Find(close_call, st_line, st_col, end_line, end_col, True, True) = False Then
     
                    If .Find("Form_Close", st_line, st_col, end_line, end_col, True, True) = True Then
     
                        .InsertLines st_line + 1, vbCrLf & vbTab & close_call
     
                    Else
     
                         cl_ret = .CreateEventProc("Close", "Form")
                        .InsertLines cl_ret + 1, vbCrLf & vbTab & close_call
     
                    End If
     
                    save_flag = acSaveYes
     
                End If
     
                st_line = 0
                st_col = 0
                end_line = 0
                end_col = 0
     
            End With
     
        End With
     
        Set frm = Nothing
     
        DoCmd.Close acForm, Application.CurrentDb.Containers("Forms").Documents(i).Name, save_flag
     
    Next i
     
    End Sub
    HTH
    Testimonial:
    pootle flump
    ur codings are working excelent.

  15. #15
    Join Date
    Jan 2007
    Location
    California, USA
    Posts
    520
    George,
    I'm wondering if you are doing this to your forms so they can work like a pop-up. Have you tested it on a form or two? Is border = 1 a no border form? The question in, what are you after here when you get all these forms changed?

Posting Permissions

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