Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2003
    Location
    Londo, UK
    Posts
    20

    Unanswered: Changing state of textbox when checkbox clicked

    When a user clicks on a checkbox I want several text boxes and one combobox to change colour and to be emptied of data and locked on one record only.

    I have managed to change the colour but it does it on all the records, using in Backcolor=255 in the AfterUpdate event (Not the colour of choice but will do for testing). and also it does not return to normal when I uncheck it. I suppose that this needs an If, Else, Then coding.

    I also tried me.textboxname.enabled = Not Me.mycheckboxname this also worked but on all records in the underlying query.

    For the combobox, do I need to create a blank entry in the underlying table, then how do I get it to change to that value when the checkbox is clicked.
    Janet

  2. #2
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Check out the conditional formatting of a field.

    Note also that you can change Conditional formatting to "Expression" and enter something like [MyFieldName] = "SomeValue" and have it change to your specific colors. For example, I'll have a Date type field and base conditional formatting as such [MyDateField]<Date() and then set the color to red.

    Conditional Formatting may not work though on unbound fields and will produce the same colors for all unbound fields if you're using a continuous form. Unbound fields can be tricky when trying to format specific record colors to show differently. I will usually try to base colors on bound fields but if done correctly, you can do it on unbound fields as well (usually in a single form).

    Otherwise I try to use bound fields for continous forms for coloring.

    As a last note, Conditional Formatting allows you only 3 conditions for coloring but you can get fancy and use multiple expresssions to produce 1 of the 3 colors. Hope that makes sense.

    I personally like the ability to disable a field (using conditional formatting) based on certain values. Note again, you can use conditional formatting to change a color of a field based on the value of a DIFFERENT field (just use an expression as demonstrated above except the expression is based on another field.)
    Last edited by pkstormy; 01-16-10 at 23:30.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Aug 2003
    Location
    Londo, UK
    Posts
    20
    Having slept on this, I have altered my form slightly, so what I want to do is slightly different.
    BTW by conditional formatting do you mean If..Else..EndIf coding?

    OK. As the three textboxes are populated by the choice made in the combobox, I have locked and disabled these.

    So what I want to do, is when the Cancelled checkbox is ticked YES, to change the combobox and the three textbox's values to blank, and disable the combobox. Then later if the Cancelled checkbox is unchecked to NO, enable the combox so that a choice can be made and the three textboxes populated from the combobox.

    If I do succeed in this will the underlying query have blank entries in the three textbox and combobox fields? I have found that I can't create a record in the tblBook that is blank.

    Is the value NULL equal to blank?
    Janet

  4. #4
    Join Date
    Aug 2003
    Location
    Londo, UK
    Posts
    20

    Smile

    Hi. Thanks for your help. I have been able to get the form to behave as I wish. I put the following code in the Update event of the checkbox.

    Private Sub Cancelled_AfterUpdate()
    If Me.Cancelled = -1 Then
    Me.Combo24.Value = Null
    Me.Price.Value = Null
    Me.Frequency.Value = Null
    Me.No.Value = Null
    Else
    Me.Combo24.Enabled = True
    End If
    End Sub.

    This works a treat. The underlying query is also blanked out.
    When the user cancels the Cancelled (if you see what I mean) then the combobox is enabled and the text fields are again populated from there.
    Janet

Tags for this Thread

Posting Permissions

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