Use VBA to open the form in design view, make the changes and use
acSaveYes.
Here is sample code to change the ribbon property of all forms in a
database.
Sub ChangeRibbonName()
Dim doc As Document
Dim db As DAO.Database
On Error Resume Next
Set db = CurrentDb()
For Each doc In db.Containers("Forms").Documents
DoCmd.OpenForm doc.Name, acDesign
Forms(doc.Name).RibbonName = "MyRibBasic"
DoCmd.Close acForm, doc.Name, acSaveYes
Next doc
Set db = Nothing
End Sub
-------------------------------------
Sample code to change properties of controls
Sub ChangeSomethingOnControls()
Dim doc As Document
Dim db As DAO.Database
Dim ctl As control
'some properties don't exist for some types of controls
On Error Resume Next
Set db = CurrentDb()
For Each doc In db.Containers("Forms").Documents
DoCmd.OpenForm doc.Name, acDesign
For Each ctl In Forms(doc.Name).Controls
If ctl.ControlTipText = "Click to sort, click again to
reverse
the sort." Then
ctl.ControlTipText = "Click to toggle."
End If
If ctl.Name = "cmdRefresh" Then
ctl.ControlTipText = "Refresh screen."
End If
If ctl.Name = "cmdFirst" Then
ctl.ControlTipText = "Go to first record."
End If
For Each ctl In Forms(doc.Name).Controls
If ctl.Name Like "*date" Or ctl.Name Like "date*" Then
ctl.ShowDatePicker = 1
Else
ctl.ShowDatePicker = 0
'Debug.Print ctl.ShowDatePicker 1 = on, 0 = off
End If
For Each ctl In Forms(doc.Name).Controls
If ctl.ControlType = acTextBox Or ctl.ControlType =
acComboBox
Then
If ctl.SpecialEffect = 2 Then
ctl.SpecialEffect = 0
End If
End If
Next ctl
DoCmd.Close acForm, doc.Name, acSaveYes
Next doc
Set db = Nothing
Set ctl = Nothing
End Sub
-----------------------------
Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
salmonella said:
We are still not on the same page
Please forget about tables or making changes in design view. my
question
is
if i make a change with VBA to the property of a form, while the form
is
in
formview, what can i do so that that change is saved with the from.
I can make the changes to the forms property, they look great and then
i
close the forms with DoCmd.close acForm, "formname", acSaveYes and it
does
not save a thing- all the properties default to the original ones.
Surely
there must be a simple answer to this.
thanks....
:
The acSaveYes is for saving changes to the design of the form, not for
saving changes to data. Changes to data need to be saved in a table.
Each
time the form is opened it gets its data from a table.
Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
Thanks for the suggestion Jeanette - it will work -but still not
what I
am
looking for (but may end up having to do it this way).
What I really need to know is whether once I change the text of a
label's
caption with VBA (while in form view) can I save the form, and will
the
label's new caption be saved also.
It appears that this is not possible...... is it???
Seems strange that the acsaveYES argument of the close method will
not
do
this.
thanks
:
Yes, much clearer.
To do what you want, store the user's entry for field1 in a table
built
for
that purpose.
When the form opens, you can do a dlookup to that table to get the
text
for
the label caption.
On the load event of the form put this code-->
Me!label1.Caption = Nz(DLookup("[FieldName]", "TableName"),"")
Replace the obvious with your own names.
Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
Sorry about all this- this is what I have:
I have a form called form1
on form1 is a field called field1 with a label called label1
I also have on the form a button called button1
The idea is that the user enters a value in field1, clicks
button1
and
the
caption of label1 is changed to the value of field1:
the onclick event for button1 is:
If Not IsNull(Me!field1) Then
Me!label1.Caption = Me!field1
End If
This works fine and the value of field1 is now the caption of
label1
There is another button on form1 that will open form2
form 2 has an on load event that closes form1 with the following
code:
DoCmd.close acForm, "form1", acSaveYes
form1 closes just fine but the new label1 value is lost when I
open
it
again
hope this is clearer
:
On Sat, 19 Sep 2009 11:26:01 -0700, salmonella wrote:
thanks for the reply- however, it did not work.
i have a control that changes the caption of a label, I close
the
form
with
the commend you gave and when I open the form back up the
change
is
gone and
original label caption is there.
I have allow design changes set to all views.
can you think of anything else?
thanks
:
On Sat, 19 Sep 2009 07:53:01 -0700, salmonella wrote:
can someone show with VBA how to permanently change the
caption
of
a
label so
that next time I open the database it will appear on the
label.
the below don't seem to do it,
Me!name.Properties("caption") = "new caption"
or
me!name.caption = "new caption"
thanks
Using VBA?
From a different form?
DoCmd.OpenForm "FormName", acDesign, , , , acHidden
Forms!FormName!LabelName.Caption = "New caption text"
DoCmd.Close acForm, "FormName", acSaveYes
From the same form?
Me!LabelName.Caption = "New Caption"
DoCmd.Close acForm, "FormName", acSaveYes
When you next open the form, the label will display the new
caption.
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Is this to change the caption of a label on the same form as the
code
or on a different form?
Why don't you tell us the Access version you are using and post
your
exact code (by copying and pasting it), as what I suggested
works
perfectly for me.