Results 1 to 5 of 5
  1. #1
    PinkLady50 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2017
    Posts
    171

    Enable/Disble a control for data entry

    I have a form which displays some background information on medial personnel contracts before the user completes the data entry portion.


    I have a field call IndCov which tells the user if it is an Individual or Coverage position.

    If it is an individual then the control called txtIndHours should be enabled and if it is Coverage then txtCovHours should be enabled and the other one in both cases would be disabled. This helps me control the data input.

    My logic is only partially working. When the IndCov field shows Individual it is graying out the txtCovHours as it should. The problem I am having is when the user changes the Contract Number, Task Order or ClIN fields which provide the background information, the Enabling and Disabling are not changing when the IndCov field changes.

    Code:
    Private Sub cboContractNum_Click()
            Me.cboContractNum = Me.cboContractNum.Column(0)
            Me.txtContractor = Me.cboContractNum.Column(1)
            Me.txtMATO = Me.cboContractNum.Column(2)
            Me.cboTO.Requery
            Me.cboCLIN.Requery
    End Sub
    Private Sub cboTO_Click()
            Me.txtTOStart = Me.cboTO.Column(1)
            Me.txtTOEnd = Me.cboTO.Column(2)
            Me.txtMTF = Me.cboTO.Column(3)
            Me.txtCOR = Me.cboTO.Column(4)
            Me.cboCLIN.Requery
            
    End Sub
    Private Sub cboCLIN_Click()
            Me.txtLaborCat = Me.cboCLIN.Column(3)
            Me.txtSite = Me.cboCLIN.Column(4)
            Me.txtClinic = Me.cboCLIN.Column(5)
            Me.txtIndCov = Me.cboCLIN.Column(6)
                 If Me.txtIndCov = "Individual" Then
                    Me.txtCovHours.Enabled = False
                 Else
                    Me.txtIndHours.Enabled = False
                 End If
    End Sub
    I would appreciate any help you can provide!

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Use the AfterUpdate event for textboxes or comboboxes. Use the OnClick for command buttons and option groups.

  3. #3
    PinkLady50 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2017
    Posts
    171
    aytee111
    I tried the AfterUpdate but my comboboxes would not work properly so I put them back the way they were and they are working again. I tried the following code on the OnDirty event and AfterUpdate thinking that would help when the value changes but that didn't work either.

    Code:
                 Private Sub txtIndCov_OnDirty()
             If Me.txtIndCov = "Individual" Then
                 Me.txtCovHours.Enabled = False
              Else
                    Me.txtIndHours.Enabled = False
                    Me.txtIndCov.SetFocus
               End If
    End Sub
    It's working in the cboCLIN_Click() but it is not updating when the field changes.

    Any other suggestions....

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    I wonder if conditional formatting would do it?

    I am unsure as to when this action should happen. Your comment "I have a field call IndCov which tells the user if it is an Individual or Coverage position" is saying that this is a display field and the enable/disable will happen at the same time as this field is populated. Or is it entered by the user?

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I, too, suggest the after update event for the combo boxes.


    Rules:
    When a contract changes, clear Task Order, ClIN, txtIndHours and txtCovHours fields, then set the enabled status of txtIndHours and txtCovHours
    When a Task Order changes, clear ClIN, txtIndHours and txtCovHours fields, then set the enabled status of txtIndHours and txtCovHours
    When a ClIN field changes, set the enabled status of txtIndHours and txtCovHours


    In a COPY of your dB, try the following code. Comment out the "_click" events.
    Code:
    Private Sub cboContractNum_AfterUpdate()
    '   Me.cboContractNum = Me.cboContractNum.Column(0)   '<<-- setting a control equal to itself???
        Me.txtContractor = Me.cboContractNum.Column(1)
        Me.txtMATO = Me.cboContractNum.Column(2)
    
        'changes made to the contract so clear the combo boxes
        Me.cboTO = Null
        Me.cboTO.Requery
    
        Me.cboCLIN = Null
        Me.cboCLIN.Requery
    
        'since you don't know at this point if Individual or Coverage position,
        ' clear txtCovHours and txtIndHours controls and disable both
        Me.txtCovHours = Null   'or maybe 0 (zero)
        Me.txtCovHours.Enabled = False
        Me.txtIndHours = Null   'or maybe 0 (zero)
        Me.txtIndHours.Enabled = False
    End Sub
    
    Private Sub cboTO_AfterUpdate()
        Me.txtTOStart = Me.cboTO.Column(1)
        Me.txtTOEnd = Me.cboTO.Column(2)
        Me.txtMTF = Me.cboTO.Column(3)
        Me.txtCOR = Me.cboTO.Column(4)
        Me.cboCLIN.Requery
    
        'since you don't know at this point if Individual or Coverage position,
        ' clear txtCovHours and txtIndHours controls and disable both
        Me.txtCovHours = Null   'or maybe 0 (zero)
        Me.txtCovHours.Enabled = False
        Me.txtIndHours = Null   'or maybe 0 (zero)
        Me.txtIndHours.Enabled = False
    
    End Sub
    
    Private Sub cboCLIN_AfterUpdate()
        Me.txtLaborCat = Me.cboCLIN.Column(3)
        Me.txtSite = Me.cboCLIN.Column(4)
        Me.txtClinic = Me.cboCLIN.Column(5)
        Me.txtIndCov = Me.cboCLIN.Column(6)
    
        If Me.txtIndCov = "Individual" Then
            Me.txtCovHours = Null   'or maybe 0 (zero)
            Me.txtCovHours.Enabled = False
        Else
            Me.txtIndHours = Null   'or maybe 0 (zero)
            Me.txtIndHours.Enabled = False
        End If
    End Sub

    You also might need code in the form current event:
    Code:
    Private Sub Form_Current()
        Me.txtIndHours.Enabled = Me.txtIndCov = "Individual"
        Me.txtCovHours.Enabled = Not (Me.txtIndCov = "Individual")
    
        '    If Me.txtIndCov = "Individual" Then
        '        Me.txtIndHours.Enabled = True
        '        Me.txtCovHours.Enabled = False
        '    Else
        '        Me.txtIndHours.Enabled = False
        '        Me.txtIndHours.Enabled = True
        '    End If
    
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Lock control after data entry
    By Scott_80 in forum Programming
    Replies: 12
    Last Post: 01-07-2015, 03:35 PM
  2. Replies: 1
    Last Post: 11-29-2014, 12:23 PM
  3. Tab Control for Data Entry Form
    By RayMilhon in forum Forms
    Replies: 6
    Last Post: 10-13-2014, 03:36 PM
  4. Replies: 3
    Last Post: 10-21-2013, 10:51 AM
  5. Replies: 1
    Last Post: 04-18-2012, 11:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums