none
Keep a textbox hiden and a checkbox unchecked when I open a new register. RRS feed

  • Question

  • Hello, everyone.

    I have a simple problem, but that keeps buggin' me.

    I have a form with a Checkbox. When I select this checkbox, it shows and enables a hidden textbox. Nothing wrong there.

    The problem is, when I open a new register, if the checkbox is checked on the previous one, it will continue checked in the new one, with the textbox shown.

    I would like that everytime I open a new register, the checkbox go unchecked and the textbox stays hidden by default. Sometimes the checkbox stays unchecked, but the textbox is visible anyway.

    I've tried to set default settings, but it didn't work.

    The code is as simple as it seems:

    Private Sub Checkbox1_OnClick()

    If Me.Checkbox1.Value = True Then
      Text1.Visible = True

    Else
      Text1.Visible= False

    End If
    End Sub

    I've tried to set it unchecked on the form's "After Update", but no success.

    Private Sub Form_AfterUpdate()

    Me.Checkbox1.Value = False
     Text1.Visible = False

    End Sub

    I'm probably missing something, but I can't see what.

    Thanks for your help.


    Thursday, September 3, 2015 12:57 AM

Answers

All replies


  • The problem is, when I open a new register, if the checkbox is checked on the previous one, it will continue checked in the new one, with the textbox shown.

    What do you mean by a 'new register?    ' I know of no such term in Access.   Do you mean a new form or a new instance of your database?

    Build a little, test a little

    Thursday, September 3, 2015 1:06 AM
  • So when the form opens you want the text box not visible and the check box unchecked.

    The code for that belongs in the forms “On Open” Event.

    Private Sub Form_Open(Cancel As Integer)
    Me.Checkbox1 = 0
    Me.Text1.Visible = False

    End Sub


    If this post answered or helped you find the answer to your question, please mark it as such for other Forum users knowledge.

    Thursday, September 3, 2015 4:00 PM
  • Hi. If you're dealing with an unbound control, I would suggest using the Current event as well. Just my 2 cents...
    Thursday, September 3, 2015 4:10 PM
  • I'm sorry, english is not my main language, neither is my Access' languge, and I used a literal translation.

    I mean every time I click on "Add a new Record", the box will be visible on the next instance.
    Thursday, September 3, 2015 6:24 PM
  • Hi. If you try your code in the Current event, in addition to where you already have it now, then it should fire when you go to a new record too. Just a thought...
    Thursday, September 3, 2015 6:34 PM
  • So when the form opens you want the text box not visible and the check box unchecked.

    The code for that belongs in the forms “On Open” Event.

    Private Sub Form_Open(Cancel As Integer)
    Me.Checkbox1 = 0
    Me.Text1.Visible = False

    End Sub


    If this post answered or helped you find the answer to your question, please mark it as such for other Forum users knowledge.



    I think this will cause anomalous errors for the users as it will change the existing values in the Table for the Checkbox and the visible property will be overridden by any subsequent code call to change it. Each record will need to apply the proper visible format based on the value of the records checkbox.

    Just takes a click to give thanks for a helpful post or answer.
    Please vote “Helpful” or Mark as “Answer” as appropriate.
    Chris Ward
    Microsoft Community Contributor 2012


    • Edited by KCDW Thursday, September 3, 2015 6:45 PM
    Thursday, September 3, 2015 6:45 PM
  • Try the following procedures:

    Private Sub Text1_SetVisible()
    
        'Handle focus if Text1 is the active control and is about to be hidden
        If (Not Me.Check1 And Me.ActiveControl.Name = "Text1") Then
            Me.Check1.SetFocus
        End If
        
        Me.Text1.Visible = Me.Check1
        
    End Sub
    
    Private Sub Check1_AfterUpdate()
        
        Text1_SetVisible
        
    End Sub
    
    Private Sub Form_Current()
        
        Text1_SetVisible
        
    End Sub

    It is assumed that Check1 is a bound control.  Each time you move to a new record the default value should be False (Not Checked).  The Form_Current event will handle hiding your text box.

    If you are scrolling through existing records, again, the Form_Current event will handle the display of the text box depending on the value of Check1.

    When Check1 is updated, the Check1_AfterUpdate event will handle the display of the text box.





    • Edited by RunningManHD Thursday, September 3, 2015 7:19 PM
    Thursday, September 3, 2015 7:14 PM