Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2010
    Location
    UK
    Posts
    160

    Unanswered: 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

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    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!

  3. #3
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •