Is there a way to update all exisiting forms back/fore color with code in db?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vikki McCormick
    New Member
    • Aug 2010
    • 46

    #1

    Is there a way to update all exisiting forms back/fore color with code in db?

    I am new to vba. I have 2 old Access databases that were developed over time. All forms have varying color and design. I need to add a picture, and update all forms to the same color and design.

    Is there some way to do this with a function?

    I was trying to loop through msysobjects and update properties but it's not working.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32669

    #2
    There certainly is Vikki.

    CurrentProject. AllForms would be your starting point for this. Let us know if you need any more detail.

    Welcome to Bytes!

    Comment

    • Vikki McCormick
      New Member
      • Aug 2010
      • 46

      #3
      NeoPa

      Thanks. Cool. That is good to know. It might not be the best approach, but I used the Forms object. I also had to update all the Title text, combo boxes etc. to improve the look of the User Interface. So I wrote something that checked to see if there were labels, combos, commands, etc., then applied a standard design. I made it our standard format tool. Guess I will have to try and refine it using the allforms command.

      The good news, it all worked till I had to create a control and load a picture. I have not gotten that working yet. Any suggestions for that let me know. I just want to insert an banner image at the top of the form. I was trying to use LoadPicture, but the program stops in the middle with no error message.

      Thanks again.

      Vikki

      Example:
      Code:
      Forms(myForm).Detail.BackColor = RGB(192, 192, 192)
      For i = 1 To 100
         If funControlExists(Forms(myForm), myLabel) = True Then
         Forms(myForm).Controls(myLabel).FontName = "Tahoma"
         Forms(myForm).Controls(myLabel).FontSize = 10
         Forms(myForm).Controls(myLabel).FontBold = 1
         Forms(myForm).Controls(myLabel).ForeColor = 0
           End If
         myLabel = "Label" & i
         Next i
      Last edited by NeoPa; Aug 7 '10, 01:54 PM. Reason: Please use the [CODE] tags provided

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32669

        #4
        The Forms collection is limited for your needs in that it contains only those forms that are currently opened.

        As for the new question, this should be posted in its own thread. Multiple questions in the same threads just get messy, which is why we don't allow it here. Before posting it again, you may want to make your situation a little clearer. More of the code would be helpful to give it context, and a clearer description of what happens when you run it would be too.

        Comment

        • Vikki McCormick
          New Member
          • Aug 2010
          • 46

          #5
          Yes. I open the form first. I will start a new thread for my other question, and post my program. You will probably see a lot that could be written better.

          Thanks again.

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            The following code can be used as a Template and will show you how to Modify specific Controls on every Form in your Database. Any questions, feel free to ask.
            Code:
            Public Function fUpdateForms()
            On Error Resume Next
            Dim intFrmCtr As Integer
            Dim ctl As Control
            Dim frm As Access.Form
            Dim strFormName As String
            
            For intFrmCtr = 0 To CurrentDb.Containers("Forms").Documents.Count - 1
              strFormName = CurrentDb.Containers("Forms").Documents(intFrmCtr).Name
                DoCmd.OpenForm strFormName, acDesign, , , , acHidden
                  For Each ctl In Forms(strFormName).Controls
                    Select Case ctl.ControlType
                      Case acLabel
                        ctl.FontSize = 16
                      Case acTextBox
                        ctl.BackColor = vbRed
                      Case acCommandButton
                        ctl.Caption = "Testing"
                      Case acComboBox
                        ctl.SpecialEffect = 2       'Sunken
                    End Select
                  Next
                  DoCmd.Close acForm, strFormName, acSaveYes
            Next
            End Function
            The critical sequence is as follows:
            1. Open each Form in the Database in Design View and Hidden Mode.
            2. For each Form, loop thru all the Controls on the Form.
            3. Determine each Control's Type on every Form.
            4. Set specific Properties depending on the Control Type.
            5. Close/Save each Form.

            Comment

            • Vikki McCormick
              New Member
              • Aug 2010
              • 46

              #7
              Wow. It helps to know something. Yes this will work well. Thanks.

              Comment

              • ADezii
                Recognized Expert Expert
                • Apr 2006
                • 8834

                #8
                You are quite welcome. Any questions, feel free to ask.

                Comment

                Working...