Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2012
    Posts
    23

    Question Unanswered: Default Properties for Control

    Good evening,

    I have textboxes that are set to enabled = false or true by default. During runtime I enable / disable some of them. I need to restore them to defaults at some point during runtime. Is there a way to access default properties that I see in Design View's Property Sheet?

    Thank you.

  2. #2
    Join Date
    Oct 2009
    Posts
    204
    you could set code anywhere during a procedure or action that would do this.

    Code:
    me.textbox.enabled=true
    or
    me.textbox.enabled = false

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    depends why you are enabling/disabling a text box
    normally I'd expect to see the call to that action absed on an eventr in a form AND when displaying the row based on whatever is the rerason to hide


    say you have a checkbox, called MyCheckBox and you want to enable if checked, disable if not
    if the forms on current event set the state for the current row
    in the MyCheckBox on click event set the state for the current row.
    in both cases I'd suggest you call a function that sets the state
    eg
    private sub SetControlState()
    if MyCheckBox.value = true then
    controlx.enabled = true
    controly.enabled = true
    controlz.enabled = true
    else
    controlx.enabled = false
    controly.enabled = false
    controlz.enabled = false
    endif
    end sub

    or another way
    controlx.enabled = MyCheckBox.value
    controly.enabled = MyCheckBox.value
    controlz.enabled = MyCheckBox.value

    you could also use the NOT construct to say set to false if true
    controlz.enabled = NOT MyCheckBox.value
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Jan 2012
    Posts
    23
    Well, user changes controls on the form to run different reports. However, I need a way to reset all these controls to defaults when he click on "Clear" button. The problem is that some of them are disabled by default while others are enables. I can either store default state in variable string / array on load, make function SetDefaultControlState() kind of like you said healdem or maybe I can access defaults directly somehow to avoid all the hustle of setting every control... i have over 20 on some of the forms.
    Last edited by DavidKi; 11-16-12 at 11:43.

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so these controls are not bound to a column in a table...
    if so then 'just' palce your enable/disable code in a suitable button control's on click event
    I'd rather be riding on the Tiger 800 or the Norton

  6. #6
    Join Date
    Jan 2012
    Posts
    23
    Nope, not bound. I can see all the default states in Design View, just was wondering if I can access them somehow because they never change no matter what I do to controls during runtime. Oh, well hundreds of lines of enabled / disabled, here I come...

  7. #7
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    default states WTF?
    the nature of the object model that Access uses means that virtually any property or method an object exposes can be manipulated by program.

    so if you want to enable / disable a control or series of controls, then write some code that sets the new appropriate value based on whatever business logic that your proposed action requires.

    so if your user is to press a button to enable or disable other controls place some code in that buttons on click event that takes the appropriate action. remember that if you programatically change a buttons enabled state you need to make certain that the user can toggle the state. the example in post #3 should get you most of the way you want to go.
    I'd rather be riding on the Tiger 800 or the Norton

  8. #8
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Quote Originally Posted by DavidKi View Post

    I can see all the default states in Design View, just was wondering if I can access them somehow because they never change no matter what I do to controls during runtime.
    These default states you keep speaking of is a concept we speak of in development, not an Access Property!

    Bottom line, if you want to modify Properties at Runtime, then return them to their prior state, you'll have to write code to do that!

    Access/VBA is like any other programming language, you simply have to work within its rules! If all of these Controls are Unbound, as Post #6 suggests, behind your 'reset button' simply Close the Form in question and then Re-open it. Everything will be set as it is in the Properties Pane.

    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

  9. #9
    Join Date
    Jan 2012
    Posts
    23
    I'm working on function to reset control properties now based on control name. For example, txtNameT txtNameF where T/F stands for default enabled state. In the function I Left(Control.NAME, 3), Right(Control.NAME, 1) to get defaults. Thanks guys!

Posting Permissions

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