Change Forms background picture at runtime

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • seraieis
    New Member
    • Apr 2008
    • 60

    Change Forms background picture at runtime

    Hi all,

    I have an Access database with roughtly 70 different forms that I need to change the background image for. Now, short of opening all these forms individually, and changing the "Picture" property one by one, is there a fast way of changing these?

    I know I can do this:
    Code:
        DoCmd.OpenForm "Account", acDesign
        Debug.Print Forms!Account.Picture
        DoCmd.Close acForm, "Account", acSaveYes
    But what I'm looking at doing is more like this, however I know this doesn't work:
    Code:
        Dim x as Variant
        x = "Account"
        DoCmd.OpenForm x, acDesign
        Debug.Print Forms!x.Picture ' fails on this line
        DoCmd.Close acForm, x, acSaveYes
    Is there a faster way of doing this?

    Thanks in advance!
  • seraieis
    New Member
    • Apr 2008
    • 60

    #2
    Nevermind. Figured it out (finally!).

    Code:
        x = "Account"
        DoCmd.OpenForm x, acDesign
        Forms.item(x).Picture = "\\wdcapp118\chcdata\Sltudata\ASLDB\SYS\bkgd.jpg"
        DoCmd.Close acForm, x, acSaveYes

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      The following code will:
      1. Open all the Forms in the Current Database in Design Mode, Hidden
      2. Dynamically changne the Picture Property of the Form to Soap Bubbles.bmp
      3. Dynamically change set the Picture Size Mode to Stretch (1)
      4. Close the Form while Saving it

      Code:
      Dim intNumOfForms As Integer
      Dim intFrmCtr As Integer
      Dim strFormName As String
       
      intNumOfForms = CurrentDb.Containers("Forms").Documents.Count
      
      For intFrmCtr = 0 To intNumOfForms - 1
        strFormName = CurrentDb.Containers("Forms").Documents(intFrmCtr).Name
          DoCmd.OpenForm strFormName, acDesign, , , acFormEdit, acHidden
            Forms(strFormName).Picture = "C:\Windows\Soap Bubbles.bmp"
            Forms(strFormName).PictureSizeMode = 1    'Stretch
              DoCmd.Close acForm, strFormName, acSaveYes
      Next

      Comment

      Working...