Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369

    Question Unanswered: toggle text field: enabled/disabled

    hi, I would like an example code on how to toggle a text field to be enabled with white background color, or disabled with grey background color.

    The function will be to either allow manual editing in a text box, hence disabling the corresponding percentage-value-list in a combo box, or to disable editing the text field, having it calculate a value that includes looking up the value in the then enabled combo box.

    I think a toggle button beside the text field would do, I am not getting any wizard/options when making the button, though, and have not made any toggle functions myself earlier.

    I recall having seen a very elegant/simple solution on a Word template once, something that would trigger the opposite state of the curernt state... Cannot remember what it was, though.

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    Your going to have to be somewhat more specific of exactly what you are trying to accomplish. I think I understand what you are trying to do but not exaclty sure. Please supply a little more information.


  3. #3
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369
    Originally posted by CyberLynx
    Your going to have to be somewhat more specific of exactly what you are trying to accomplish. I think I understand what you are trying to do but not exaclty sure. Please supply a little more information.

    I only need to know the vba code to switch a state to the opposite of two possible states, regardless of what is the current state. It is a common vb trick that also works in vba/access, I have seen it in usein Word templates, but cannot seem to remember just what it was.

    Something like:

    mystate <> mystate,
    or
    mystate = not mystate

    something similar to that.
    It only works in On/Off situations, with max two possible states, like "toggle between A and B, enabled and disabled"

    Sorry for my bad example, do not know how to describe this better...

  4. #4
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713

    Re: toggle text field: enabled/disabled

    Originally posted by kedaniel
    hi, I would like an example code on how to toggle a text field to be enabled with white background color, or disabled with grey background color.

    The function will be to either allow manual editing in a text box, hence disabling the corresponding percentage-value-list in a combo box, or to disable editing the text field, having it calculate a value that includes looking up the value in the then enabled combo box.

    I think a toggle button beside the text field would do, I am not getting any wizard/options when making the button, though, and have not made any toggle functions myself earlier.

    I recall having seen a very elegant/simple solution on a Word template once, something that would trigger the opposite state of the curernt state... Cannot remember what it was, though.
    Something like:

    If ToggleCondition then
    MyTextBox.Enabled=True
    else
    MyTextbox.Enabled=False
    endif

    Is this what you're thinking?

  5. #5
    Join Date
    Nov 2003
    Posts
    1,487
    As a sample....Create a new form. On this form place two TextBoxes and name them Txt1 and Txt2. Make sure the Enabled property of Txt2 is set to False.

    Now place a Command Button onto the form (named Command1). In the OnClick event of the Command Button, place the following code like shown below:
    Code:
    Private Sub Command1_Click()
       Me.Txt1.Enabled = Not Me.Txt1.Enabled
       Me.Txt2.Enabled = Not Me.Txt1.Enabled
    End Sub
    Hope this helps ...

  6. #6
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369

    Question

    Originally posted by CyberLynx
    Code:
    Private Sub Command1_Click()
       Me.Txt1.Enabled = Not Me.Txt1.Enabled
       Me.Txt2.Enabled = Not Me.Txt1.Enabled
    End Sub
    Thanks. In my case, when enabling the first field, what happens is that the percentage value entered there (manually) is going to update the calculation of the current value in the second ("disabled" field... So both fields need to be updateable, but I want to - at least visually by changing the background color and removing the tab stop - disable user input , or clearly discourage it. It could be that simply on the KeyDown event for each field, this function will trigger change in color coding for both fields and "enable" the one being edited.

    Moreover, other unbound text fields are doing calculations on the second field, the one that either contains a manually entered number (currency), or that contains a calculated number based on the percentage in the first field multiplied with another value.

    This means that I cannot disable or lock the second field, I guess.

    Concern: I am thinking that if the percentage calculation from the first field is the one that is correct for the current record, and I use the KeyDown event, then a user cannot select the value in that second field, press crtl+c to copy the value without that field being enabled...

    Any better/other ways of handling this?.
    Thanks for your help/thoughts/advices.

  7. #7
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369

    Thumbs up

    I chose to skip enabling/disabling, only shift the focus, change background color, like parts of Rockeys example at

    http://www.dbforums.com/showthread.p...23#post3614423

    (since the fields are part of other calculations and must be enabled/cannot be completely locked. What I was thinking about was to block the user from making changes, not the other automatic functions.

    The part I dropped is the first one:
    Me.txtCalcSelOurComm.Enabled = Not Me.txtCalcSelOurComm.Enabled
    Me.txtour_sales_commission.Enabled = Not Me.txtour_sales_commission.Enabled

    - the rest is working sufficiently for my purpose now:
    (only added one line to set a formula for one of the cases)

    If Me.chkcomm_manual = True Then
    Me.txtCalcSelOurComm.BackColor = 15000804
    Me.txtour_sales_commission.BackColor = 12632256
    Me.txtCalcSelOurComm.SetFocus
    Else
    Me.txtCalcSelOurComm.BackColor = 12632256
    Me.txtour_sales_commission.BackColor = 8454143
    Me.txtCalcSelOurComm = ("field calc/formula here")
    Me.txtour_sales_commission.SetFocus
    End If

Posting Permissions

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