VBA Field Label Caption Change won't stay (1 Viewer)

Monsora83

Registered User.
Local time
Today, 04:00
Joined
May 16, 2011
Messages
41
I am using:

Forms(strFormName).Controls(strFieldLabelName).Properties("Caption").Value = Me.New_Field_Label_Caption

To change the caption of some labels. The code works fine so if I run it then open the form, the label has the proper new caption, however if I close and reopen the database, it revents to its original caption.

Will I just have to use an 'On Load' event for the form every time it's opened, or is there a way to make the change stick?
 

Khalid_Afridi

Registered User.
Local time
Today, 11:00
Joined
Jan 25, 2009
Messages
491
On which event you are using the code? On form Load OR current event of the form might solve the problem.
 

Monsora83

Registered User.
Local time
Today, 04:00
Joined
May 16, 2011
Messages
41
On which event you are using the code? On form Load OR current event of the form might solve the problem.

Currently I'm not using an On Event. I have a button set up on another form that udates all the changes for captions in the database.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 09:00
Joined
Sep 12, 2006
Messages
15,672
well what you are doing is temporarily overwriting the captions from the values you set when you designed the form, so they won't "stick".

The question is - why are you changing captions? What are you "really" trying to achieve?

Note that your syntax for this is unusual - which implies you got this code from somewhere without maybe fully understanding what it all meant.
 

Monsora83

Registered User.
Local time
Today, 04:00
Joined
May 16, 2011
Messages
41
The question is - why are you changing captions? What are you "really" trying to achieve?

So that users can rename the label they use as a process that will constantly be redefined as time goes, while still housing the same field data. Else I will containly be asked to change it.

Note that your syntax for this is unusual - which implies you got this code from somewhere without maybe fully understanding what it all meant.

Indeed, which is why I posted it. Googled it along with some code posting on these forms.

Users with proper privledges will be allowed to rename specific labels on a form when needed, so when the time comes to enter data, the field will be named as they want it.
 

VilaRestal

';drop database master;--
Local time
Today, 09:00
Joined
Jun 8, 2011
Messages
1,046
You would have to store the captions in a table and read and assign them in the load event of every form where they appear.

If you wanted to have mulitple language versions of a database that's the kind of thing you'd have to do too.
 
Last edited:

VilaRestal

';drop database master;--
Local time
Today, 09:00
Joined
Jun 8, 2011
Messages
1,046
Alternatively, you could open the forms in design view (in code) before setting the captions and then save it. That would fail in a compiled database and runtime only access wouldn't cope with it either.
 

missinglinq

AWF VIP
Local time
Today, 04:00
Joined
Jun 20, 2003
Messages
6,423
In order for the Caption changes to persist you'd have to open the target Form in Design View from another Form. You'd
  • Open the Target Form in Design View
  • Make Caption changes
  • Close Target Form, saving changes
The code to use would be
Code:
DoCmd.OpenForm "TargetForm", acDesign
 
 Forms("TargetForm")("TargetLabel").Caption = "Whatever You Like""
    
 DoCmd.Close acForm, "TargetForm", acSaveYes

Linq ;0)>
 

raphael99

Registered User.
Local time
Today, 01:00
Joined
Apr 6, 2015
Messages
126
I would like to have a form when loaded show a label which dynamically change the customer's name. Can you please suggest how to get it? I'm novice. Thanks
 

Users who are viewing this thread

Top Bottom