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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change forms property automatic through code on all forms in database

Status
Not open for further replies.

Romanov

Technical User
Jan 18, 2002
11
DK
Is there a way to change a properties for a number of forms ?

I like to change the background picture of all form in my database, but I don't worn't to open every form in design mode, change the Picture property and save it. So what I'm looking for is a way to do this automaticaly - Through code I hope.

Is this posible and can someone tell me how ??

I have close to 100 forms in my database soo i realy hope someone know a way to do this.

Thanks
 
Dim dbl_temp As Double
For dbl_temp = 1 To Forms.Count
Forms(dbl_temp - 1).Controls("Picturename").Picture = "newpicture.jpg"
Next dbl_temp


this will work in an mdb
Christiaan Baes
Belgium
"What a wonderfull world" - Louis armstrong
 
Hi Chrissie1

When I run the code it gives the following error :
"Microsoft can't find the field "picturename" reefered to in your expression.

Can you tell me why ??

Thanks
 
because picturename should be the name you used as you background

but if i understand you better now

then this should work better

Dim dbl_temp As Double
For dbl_temp = 1 To Forms.Count
Forms(dbl_temp - 1).Picture = "newpicture.jpg"
Next dbl_temp

Christiaan Baes
Belgium
"What a wonderfull world" - Louis armstrong
 
and a couple of small issues ...

It will only work for the Open forms, you would need some alternate address ("AllForms" | Documents("Forms") to do all form objects. "Forms(I only refers to OPEN forms.

The property is changed only for the current instance of the object. To perpetuate the change, you need to close / SAVE the object (Form) in the code.

MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Thanks - it works fine, but..... I still have a few problems. It is only looking at the forms I have open. I need to open each form, provide the changes, and the save and close it. Can you help me with this ?

My code looks like this rigth now :

Dim dbl_temp As Double
For dbl_temp = 1 To Forms.Count
DoCmd.OpenForm Forms(dbl_temp - 1).Name

Forms(dbl_temp - 1).Picture = "c:\kunder\clouds.wmf" 'New picture
Forms(dbl_temp - 1).PictureSizeMode = 1 'stretch
Forms(dbl_temp - 1).PictureType = 1 'Linked
Next dbl_temp

I have tried to open the forms by using the folloing command before applying the changes :

DoCmd.OpenForm Forms(dbl_temp - 1).Name

Thanks
 
I don't believe that chrissie1's response will work for you. You see that code will only change the Picture property of OPENED forms. And, it will not stick. Meaning that the next time the form is opened the picture property is set back to "none".

I am still researching this but I am pretty sure that those form properties that can be changed in code have to be in an opened form and closed forms properties are not available. Otherwise, as we go about in report and forms and make property changes in code the results would not necessarily be what we want the next time the form is opened.

I will let you know what I find out. Bob Scriver
 
If there is a way to open all forms from code - properly best in design mode, so that On_Open or Timer code don't start - then make the changes with the code chrisie1 surgested, and in the end saving and closing all the forms again ?

If this is posible, then property changes on all forms in the database can be done from code.

Romanov
 
everybody's a critic today, think

Dim dbl_temp As Double
For dbl_temp = 1 To Forms.Count
DoCmd.OpenForm Forms(dbl_temp - 1).Name,acdesign

Forms(dbl_temp - 1).Picture = "c:\kunder\clouds.wmf" 'New picture
Forms(dbl_temp - 1).PictureSizeMode = 1 'stretch
Forms(dbl_temp - 1).PictureType = 1 'Linked
docmd.close acform,"forms(dbl_temp-1).name
Next dbl_temp Christiaan Baes
Belgium
"What a wonderfull world" - Louis armstrong
 
chrissie1: My apologies, no criticism intended. I was referring to your posting of:

Dim dbl_temp As Double
For dbl_temp = 1 To Forms.Count
Forms(dbl_temp - 1).Picture = "newpicture.jpg"
Next dbl_temp

While I was researching the problem you reposted with the new code. My post was not aware of your new code. Bob Scriver
 
Sorry for the previous code but this should work better

Dim dbl_temp As Double
For dbl_temp = 1 To Application.CurrentProject.AllForms.Count
DoCmd.OpenForm Application.CurrentProject.AllForms(dbl_temp - 1).Name, acDesign
Forms(Application.CurrentProject.AllForms(dbl_temp - 1).Name).Picture = "c:\kunder\clouds.wmf" 'New picture
Forms(Application.CurrentProject.AllForms(dbl_temp - 1).Name).PictureSizeMode = 1 'stretch
Forms(Application.CurrentProject.AllForms(dbl_temp - 1).Name).PictureType = 1 'Linked
DoCmd.Close acForm, Application.CurrentProject.AllForms(dbl_temp - 1).Name, acSaveYes
Next dbl_temp
Christiaan Baes
Belgium
"What a wonderfull world" - Louis armstrong
 
Thanks this code works great. It will save me a lot of work when I provide changesw in my databases in the future.

Romanov
 
Just out of curiosity, why are we using a loop control variable of type 'double'?
 
Here's some DAO code that doES the same thing. It includes removal of all pictures also.
Dim db As Database
Dim docLoop As Document
Set db = CurrentDb
With db.Containers!Forms
For Each docLoop In .Documents
DoCmd.OpenForm docLoop.Name, acDesign
If Forms(docLoop.Name).Picture = "(none)" Then
Forms(docLoop.Name).Picture = "c:\pictures\yourpic.jpg"
Forms(docLoop.Name).PictureSizeMode = 1 'stretch
Forms(docLoop.Name).PictureType = 1 'Linked
Else
Forms(docLoop.Name).Picture = "(none)"
Forms(docLoop.Name).PictureSizeMode = 0 'Embedded
Forms(docLoop.Name).PictureType = 0 'Clip
End If
DoCmd.Close acForm, docLoop.Name, acSaveYes
Next docLoop
End With

Bob Scriver
 
we use a double just because i always use a double its a habit i dont like to change. I know that it is not neccessary in this case but you neve know perhaps someone has a half form in their db, if seen stranger things.
Christiaan Baes
Belgium
"What a wonderfull world" - Louis armstrong
 
hmmmmmmmmmmm, I DO like the option to 'Clear" the picture, as -used w/o some careful consideration- the routine from Chrissie1 can make part of forms difficult for my eyes. Also, if some region(s) of a form are 'highlighted' the (e.g. a BOX) with a diffferent background, the routines do not address them, so some thought needs to go into the 'wholesale' approach.

Given the diversity of graphics available for use as 'backgrounds', the seperate color scheme for "box" objects could be quite a chore. I suppose a routine could be set up to 'inspect' the FORM background as it was applied, and call an appropiate transform routine for that image type to transmorgify the color scheme and use that on box type objects.

In the short term, I'm going to relegate this to the interesting - but not widely applicable to my work. Although ... IF I ever gain employment where my supervisor has a hightly developed sense of humor, the concept of the 'cartoon-a-day' as the background for forms is intriguing?

MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Double is never necessary or appropiate for a loop counter. Loops canot be 'incremented' in fractional steps. For LARGE collections, you may need to use LONG, but the use of single, double, date, currency or other 'floating point types just incurs the overhead of coercing the value to a fixed point type.

The concept of ... perhaps someone has a half form in their db, if seen stranger things ... may be true, but I do not nelieve you can truthfully claim to have actually seen THAT particular beast.


MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
nope i neve seen it but the dbl_temp can be uesed in other instances normally i declare it public and use it all over the place. prevents me from needing to declare a int_temp, dbl_temp, lng_temp or wathever else in most cases you only need one variable and this one you can use where ever you like and i need to only declare it once

and why am i explaining what i do?? Christiaan Baes
Belgium
"What a wonderfull world" - Louis armstrong
 
how do I disagree with thee ... let me count the ways

use of 'floating point' values (at least for a loop counter) is, like beauty, entirely in the eyes of the beholder (or at least user)

As to PERHAPS the great cosmic why, could it be some hiden and perverse desire to learn, to know more of the mysteries of the life of a variable?

MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top