If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Setting a variable which remains even if reload database

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-20-12, 11:18
marcusmacman marcusmacman is offline
Registered User
 
Join Date: Sep 2010
Location: UK
Posts: 119
Setting a variable which remains even if reload database

Hi there,

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.

thanks
Mark
Reply With Quote
  #2 (permalink)  
Old 01-20-12, 12:06
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 3,446
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:
Code:
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
To retrieve the value of an existing property:
Code:
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
To change the value of an existing property:
Code:
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 Function
__________________
Have a nice day!
Reply With Quote
  #3 (permalink)  
Old 01-21-12, 12:19
Missinglinq Missinglinq is offline
Registered User
 
Join Date: Jun 2005
Location: Richmond, Virginia USA
Posts: 1,702
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 Devil's in the Details!!

All posts/responses based on Access 2000/2003
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On