Results 1 to 11 of 11
  1. #1
    2 Star Lounger
    Join Date
    Mar 2004
    Location
    Christchurch
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    unlock checkbox, require entry (2003)

    Hi, first, I have a series of checkboxes and text boxes on a form which I want to be locked by default for a record, but unlock when a "master checkbox" is ticked. Then, when one of the unlocked checkboxes is ticked, I want a particular text box (which was just unlocked) to require an entry. Conditional formatting is not available for the checkboxes, it seems I need some code to do this for me, could someone suggest generic code to do each of these tasks?

    Thank you - Roger

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: unlock checkbox, require entry (2003)

    If I understand you correctly, you want the controls to start out locked when the user moves to another record, and presumably the check boxes should be cleared. You can do this in the On Current event of the form:

    Private Sub Form_Current()
    Me.chkThis = False
    Me.chkThis.Locked = True
    Me.txtThis.Locked = True
    ...
    End Sub

    Next, you want to unlock the controls when a master check box is ticked:

    Private Sub chkMaster_AfterUpdate()
    If Me.chkMaster = True Then
    Me.chkThis.Locked = False
    Me.txtThis.Locked = False
    ...
    Else
    ' Do you want the controls to be locked again if the master check box is cleared?
    ' If so, do it here
    Call Form_OnCurrent
    End If
    End Sub

    You can check for the required values in the Before Update event of the form:

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Me.txtThis.Locked = False And IsNull(Me.txtThis) Then
    Me.txtThis.SetFocus
    MsgBox "Please enter a value!", vbExclamation
    Cancel = True
    Exit Sub
    End If
    If Me.txtThat.Locked = False And IsNull(Me.txtThat) Then
    ...
    ...
    End Sub

  3. #3
    2 Star Lounger
    Join Date
    Mar 2004
    Location
    Christchurch
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: unlock checkbox, require entry (2003)

    Hi Hans, that is very helpful, thank you. A few refinements needed. First, using the Form_Curent() code results in every new viewing of a particular record having the controls locked (and I am also having them disabled). I only want new records to start out in this state, so instead I have set the controls to be locked and disabled. The .Locked=False code then unlocks them. I am also setting .tabstop=true. This seems to work, however perhaps you can suggest a better way if there is one.

    Second, and this is the question today, I am wanting to replicate the effect of disabling the controls via conditional formatting, where the background colour and label change shade. Is there a single attribute I can set to do this, or, what are the properties that need to be set?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: unlock checkbox, require entry (2003)

    If you set the Enabled property of a control to False and leave its Locked property set to False, the control will look greyed out.

    You can add a check to the Form_Current event:

    If Me.NewRecord Then
    ...
    End If

  5. #5
    2 Star Lounger
    Join Date
    Mar 2004
    Location
    Christchurch
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: unlock checkbox, require entry (2003)

    OK I am just about there. The following code is performing the actions I want but is doing so for ALL records rather than just the current record, where have I gone wrong?

    Private Sub AcceptedToService_AfterUpdate()
    'unlocking controls when AcceptedToService is ticked
    If Me.AcceptedToService = True Then
    Me.EmailToACC.Enabled = True
    Me.EmailToACC.TabStop = True
    'enable EmailDate if EmailToACC is ticked
    If Me.EmailToACC = True Then
    Me.EmailDate.Enabled = True
    Me.EmailDate.TabStop = True
    End If
    Me.LetterToClient.Enabled = True
    Me.LetterToClient.TabStop = True
    'enable LetterDate if EmailToClient is ticked
    If Me.LetterToClient = True Then
    Me.LetterDate.Enabled = True
    Me.LetterDate.TabStop = True
    End If
    Else
    ' controls to be enabled again if AcceptedToService is cleared
    Me.EmailToACC.Enabled = False
    Me.EmailToACC.TabStop = False
    'enable EmailDate only if EmailToACC is ticked, otherwise it should be disabled
    If Me.EmailToACC = True Then
    Me.EmailDate.Enabled = False
    Me.EmailDate.TabStop = False
    Else
    Me.EmailDate.Enabled = False
    Me.EmailDate.TabStop = False
    End If
    Me.LetterToClient.Enabled = False
    Me.LetterToClient.TabStop = False
    'enable LetterDate only if EmailToACC is ticked, otherwise it should be disabled
    If Me.LetterToClient = True Then
    Me.LetterDate.Enabled = False
    Me.LetterDate.TabStop = False
    Else
    Me.LetterDate.Enabled = False
    Me.LetterDate.TabStop = False
    End If
    End If
    End Sub

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: unlock checkbox, require entry (2003)

    Is this a continuous form? A continuous form contains a single set of controls that is used to display multiple records. If you change the properties of a control, the changes apply to all visible records. The only way to change the properties of a control for individual records is to use conditional formatting, since this depends on the values of fields in the record.

  7. #7
    2 Star Lounger
    Join Date
    Mar 2004
    Location
    Christchurch
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: unlock checkbox, require entry (2003)

    No, the form is the single form view. Since Conditional Formatting is not available on a check box it appears that I am stuck? Can I not enable and disable controls on a form based on whether a check box is selected - on a "per record" basis?

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: unlock checkbox, require entry (2003)

    As mentioned before, you can use the On Current event of the form to set properties of controls as the user moves from record to record.

  9. #9
    2 Star Lounger
    Join Date
    Mar 2004
    Location
    Christchurch
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: unlock checkbox, require entry (2003)

    oh, ok. well i did start off using the form's On Current event, and it seemed that the control's properties were being altered (reset) each time i came back to view a record. i must have done something wrong so will revisit now that i have an otherwise better understanding of what to do.

    i really appreciate your replies and patience!

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: unlock checkbox, require entry (2003)

    If you want to set the properties of controls on a record-by-record basis, you should use If ... Then or Select Case in the On Current event to set the properties conditionally.

  11. #11
    2 Star Lounger
    Join Date
    Mar 2004
    Location
    Christchurch
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: unlock checkbox, require entry (2003)

    Hans, thanks for all your replies, I have finally understood what you were getting me to do, and now that I'm doing ALL the things simultaneously (rather than testing one at a time) it is working really well and exactly as I wanted.

    Regards, Roger

Posting Permissions

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