473,554 Members | 2,075 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

In VBA, how to make form properties "stick"?

1 New Member
Is there a way to update form/control properties via VBA and have them still be there after the form is re-opened?

When a textbox value is updated by the user, I need that value to be there next time the form is loaded. Sure I could store the value in the database, but this happens to be an unbound form, so I'm hoping for something simple.

The forum post Default Value set the same as last valus for field describes how how to set a control's Default Value in VBA. (I am proud to say I independently came up with the same solution as Allen Browne, though the quadruple double-quotes took some experimentation .:))

Problem is, the change does not persist. When the form is re-opened, the default value is gone.

By the way, I know properties can be "permanentl y" updated programmaticall y, because I've seen it happen. I'm not sure how, but I have had changes appear in my property sheet that I did not put there directly. I do a lot of debugging of others' VBA code, so it is possible that a breakpoint+abor t caused this, but I have not been able to (intentionally) reproduce it.
Feb 6 '08 #1
6 5680
Jim Doherty
897 Recognized Expert Contributor
Is there a way to update form/control properties via VBA and have them still be there after the form is re-opened?

When a textbox value is updated by the user, I need that value to be there next time the form is loaded. Sure I could store the value in the database, but this happens to be an unbound form, so I'm hoping for something simple.

The forum post Default Value set the same as last valus for field describes how how to set a control's Default Value in VBA. (I am proud to say I independently came up with the same solution as Allen Browne, though the quadruple double-quotes took some experimentation .:))

Problem is, the change does not persist. When the form is re-opened, the default value is gone.

By the way, I know properties can be "permanentl y" updated programmaticall y, because I've seen it happen. I'm not sure how, but I have had changes appear in my property sheet that I did not put there directly. I do a lot of debugging of others' VBA code, so it is possible that a breakpoint+abor t caused this, but I have not been able to (intentionally) reproduce it.
Have you considered having a simple config table designed to only ever contain one row ? Place your values in each field and then simply Dlookup the value you need and apply that value when the form opens?

It need not be 'one' row of course..you could have a field in it that is called Formname for instance where you store the name of the form lookup the formname correponding to the form that you are opening and retrieve the values for 'that' form if you understand me.

Regards

Jim
Feb 7 '08 #2
ADezii
8,834 Recognized Expert Expert
Is there a way to update form/control properties via VBA and have them still be there after the form is re-opened?

When a textbox value is updated by the user, I need that value to be there next time the form is loaded. Sure I could store the value in the database, but this happens to be an unbound form, so I'm hoping for something simple.

The forum post Default Value set the same as last valus for field describes how how to set a control's Default Value in VBA. (I am proud to say I independently came up with the same solution as Allen Browne, though the quadruple double-quotes took some experimentation .:))

Problem is, the change does not persist. When the form is re-opened, the default value is gone.

By the way, I know properties can be "permanentl y" updated programmaticall y, because I've seen it happen. I'm not sure how, but I have had changes appear in my property sheet that I did not put there directly. I do a lot of debugging of others' VBA code, so it is possible that a breakpoint+abor t caused this, but I have not been able to (intentionally) reproduce it.
One little trick I use fairly often is that whenever I want certain critical values/settings/properties, etc. to persist for Forms and/or Controls, I'll write them to the System Registry, when they can easily be retrieved at will, they are not stored internally, and cannot be modified without some effort.
Feb 7 '08 #3
NeoPa
32,564 Recognized Expert Moderator MVP
Try duplicating what you do as an operator.
Open the form IN DESIGN VIEW, then make changes and close/save.
Changes to the design (I assume Default Value property) during running mode are never persistent.
Feb 7 '08 #4
ADezii
8,834 Recognized Expert Expert
Is there a way to update form/control properties via VBA and have them still be there after the form is re-opened?

When a textbox value is updated by the user, I need that value to be there next time the form is loaded. Sure I could store the value in the database, but this happens to be an unbound form, so I'm hoping for something simple.

The forum post Default Value set the same as last valus for field describes how how to set a control's Default Value in VBA. (I am proud to say I independently came up with the same solution as Allen Browne, though the quadruple double-quotes took some experimentation .:))

Problem is, the change does not persist. When the form is re-opened, the default value is gone.

By the way, I know properties can be "permanentl y" updated programmaticall y, because I've seen it happen. I'm not sure how, but I have had changes appear in my property sheet that I did not put there directly. I do a lot of debugging of others' VBA code, so it is possible that a breakpoint+abor t caused this, but I have not been able to (intentionally) reproduce it.
You can 'Persist" a Default Value for a Table Field, as such:
Expand|Select|Wrap|Line Numbers
  1. CurrentDb.TableDefs("<Table Name>").Fields("<Field Name>").DefaultValue = "<Default Value>"
Feb 7 '08 #5
NeoPa
32,564 Recognized Expert Moderator MVP
As ADezii says, properties for tables (and querydefs) will persist when changed. For forms (and reports) however, they will be of instance scope only unless you update the object itself. That is you need to make the change in the form via Design-mode.
Feb 7 '08 #6
ADezii
8,834 Recognized Expert Expert
Is there a way to update form/control properties via VBA and have them still be there after the form is re-opened?

When a textbox value is updated by the user, I need that value to be there next time the form is loaded. Sure I could store the value in the database, but this happens to be an unbound form, so I'm hoping for something simple.

The forum post Default Value set the same as last valus for field describes how how to set a control's Default Value in VBA. (I am proud to say I independently came up with the same solution as Allen Browne, though the quadruple double-quotes took some experimentation .:))

Problem is, the change does not persist. When the form is re-opened, the default value is gone.

By the way, I know properties can be "permanentl y" updated programmaticall y, because I've seen it happen. I'm not sure how, but I have had changes appear in my property sheet that I did not put there directly. I do a lot of debugging of others' VBA code, so it is possible that a breakpoint+abor t caused this, but I have not been able to (intentionally) reproduce it.
Here is an example of how you can 'Persist' a Default Value for a Form Field. Let's assume you have a Field named [txtDefault] on an Active Form. Let's further assume that anytime a User modifies the value in [txtDefault], you want that value to 'Persist' and then become the new Default Value for all New Records (Form Level), until further modified. Instead of babbling on, I'll simple post the code on how this can be done, and if you have any questions, please feel free to ask. Notice specifically, the 2 Procedures where the code is placed, and the conditional statements. I'll shut up now!
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtDefault_AfterUpdate()
  2. If Not IsNull(Me![txtDefault]) Then
  3.   SaveSetting appname:="Your App Name", Section:="Control Defaults", _
  4.                         Key:="ID", setting:=Me![txtDefault]
  5. Else
  6.   SaveSetting appname:="Your App Name", Section:="Control Defaults", _
  7.                         Key:="ID", setting:=""
  8. End If
  9. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.   If Me.NewRecord Then
  3.     Me![txtDefault] = GetSetting(appname:="Your App Name", Section:="Control Defaults", _
  4.                       Key:="ID", Default:="")
  5.   End If
  6. End Sub
Feb 8 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

10
3305
by: Scott Brady Drummonds | last post by:
Hi, everyone, I'm still learning Python as I develop a medium-sized project. From my previous experience with C++, I've burnt into my mind the notion of information hiding. I'm having trouble understanding to what extent I should follow this policy in my Python code so I thought I'd ask the group. I read from a previous post that to...
8
33896
by: Mario T. Lanza | last post by:
I'm not sure what I'm doing wrong. I have a form that has mnay input fields. Before each input field is a label enclosed in custom LABEL tags. Inside my CSS I have: LABEL { width: 120px; }
77
5224
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for the moment. I'd be *very* grateful if people with any interest in multi-threading would read it (even just bits of it - it's somewhat long to go...
3
3965
by: Ken | last post by:
I have a win 2000 database of autographs and scanned photos. They are in the SAME directory. In the table, my "ImagePath" text field shows JUST the image name (i.e. "blank.jpg"). I have an image field that links to the ImagePath field. But it does not display in the form. I go in and delete the image field and add it back in and link it to...
2
5804
by: Marty | last post by:
Hi, How do we make a form "stick" to another window (something like Winamp)? I'm using C# .NET 2003. Thank you very much. Marty
17
2385
by: Peter Oliphant | last post by:
In the 'old days', we could create a pointer to an instance of a variable like so: int i = 58 ; int* i_ptr = &i ; int j = *i_ptr ; // j = 58 Now, in /clr how do we do the same? That is, if I replace '*' with '^' what do I replace '&' with to generate a 'pointer' (is 'x^' called a 'reference' per chance?) to the instance? That is:
6
1440
by: Larry Woods | last post by:
I am trying to name my submenus (MainMenu control) and they show up in the menu dropdown...like they are O.K., but when I check my controls the names are still "MenuItemX". OTOH, the top-level menu items renamed just fine. What might I be doing wrong? TIA, Larry Woods
3
2104
lwwhite
by: lwwhite | last post by:
Access 2003. I have a form (form view) with a subform (datasheet view). The form has a map_id field and each record on the subform also has a map_id field. I want the fields on the form and subform to automatically display the next available number in a defined sequence when I add a new record to either. I have been able to successfully generate...
4
9840
by: FullBandwidth | last post by:
I have been perusing various blogs and MSDN pages discussing the use of event properties and the EventHandlerList class. I don't believe there's anything special about the EventHandlerList class in this context, in fact some articles from pre-2.0 suggest using any collection class of your choice. So my questions focus more on the syntax of...
0
7605
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7530
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8047
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7570
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7893
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6156
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5441
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1141
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
845
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.