01-20-12, 11:18 #1Registered User
- Join Date
- Sep 2010
Unanswered: Setting a variable which remains even if reload database
Probably a silly question but.....
I have a couple of buttons which increase and decrease the height of a field. I would like to store the height value in the database somewhere so it is kept forever. So the next time i load the database it remebers the height i last set.
01-20-12, 12:06 #2Moderator
Provided Answers: 14
- Join Date
- Mar 2009
You can create, change, delete user-defined properties in the Properties collection of a Database object (CurrentDb). These properties are persistent (i.e. they are stored in the .mdb or .accdb file).
To create a new property:
Function CreateDbProperty(PropertyName, PropertyValue) ' ' This function is called to create a new (user-defined) property ' of the Database object. ' ' It returnd True if successfull, an error code otherwise. ' #If ERR_ON Then On Error GoTo Err_CreateDbProperty #End If Dim prpNew As Property Set prpNew = CurrentDb.CreateProperty(PropertyName, dbText, PropertyValue) CurrentDb.Properties.Append prpNew Set prpNew = Nothing Exit_CreateDbProperty: Exit Function Err_CreateDbProperty: CreateDbProperty = Err.Number Resume Exit_CreateDbProperty End Function
Function GetDBProperty(PropertyName, PropertyValue) As Long ' This function is called to get a (user-defined) property ' of the Database object. ' ' It returnd True if successfull, an error code otherwise. ' #If ERR_ON Then On Error GoTo Err_GetDBProperty #End If Dim Prop_Database As DAO.Database Dim Prop_lngRetVal As Long Set Prop_Database = CurrentDb PropertyValue = Prop_Database.Properties(PropertyName) Prop_lngRetVal = True Exit_GetDBProperty: GetDBProperty = Prop_lngRetVal Exit Function Err_GetDBProperty: PropertyValue = Null Prop_lngRetVal = Err.Number Resume Exit_GetDBProperty End Function
Function SetDBProperty(PropName, PropValue) As Integer ' ' This function is called to change the value of a (user-defined) property ' of the Database object. ' ' It returnd True if successfull, an error code otherwise. ' #If ERR_ON Then On Error GoTo Err_SetDBProperty #End If Dim Property As Property Dim Database As Database Set Database = CurrentDb Set Property = Database.Properties(PropName) Property.Value = PropValue Database.Properties.Refresh SetDBProperty = True Exit_SetDBProperty: Exit Function Err_SetDBProperty: SetDBProperty = Err.Number Resume Exit_SetDBProperty End FunctionHave a nice day!
01-21-12, 12:19 #3Moderator
Provided Answers: 19
- Join Date
- Jun 2005
- Richmond, Virginia USA
Or you could simply create a 'utility' Table and store and retrieve it from there. I use this technique to allow users to store and retrieve values such as company names, addresses, phone numbers, etc, to be used in the letterhead for Reports, but it could be used for storing things like you're talking about.
Linq ;0)>Hope this helps!
The problem with making anything foolproof...is that fools are so darn ingenious!
All posts/responses based on Access 2003/2007