control BackColor not changing

Zydeceltico

Registered User.
Local time
Today, 18:19
Joined
Dec 5, 2017
Messages
843
Hi All -

I have a form with 3 required fields. When the form opens all controls are disabled except for the first of the 3 required fields & its BackColor is set to vbYellow drawing the user attention to that cbo. Also the "Save" button is disabled. So far so good.

The user makes a selection in this combo box which triggers the On Dirty event to enable the second of the required controls and sets the second req'd control's BackColor to Yellow. The After Update event of the first control sets the BackColor of the FIRST control to vbWhite.

Same thing happens on 2nd required control after it becomes enabled. It is first yellow; a value is entered; its BackColor becomes vbWhite & 3rd required control is enabled w/ BackColor = vbYellow - - this all works up to this point - - including - at this point when 3rd control becomes Dirty - the Save button is enabled as are all other controls on the form - - this all works.

What I can't get to work is to set the 3rd required control BackColor to vbWhite using exactly the same code and I cannot figure it out.

I've tried On Change. I've tried SetFocus to another control.

Thoughts?

Thanks!

Tim
 
Consider using Conditional Formatting for textbox and combobox.

Post your code or provide db.
 
Hi Tim. We'll need to see how you're setting the colors, so we can get a hint as to why it is failing. Can you post the code, please? Thanks.


Is it similar to this?
 
Before you get too deep into this, have you considered the scenario where a prior control value is removed? I don't think I'd be using On Dirty event for a control. Before/After Update more likely. Maybe your last control is not bound? I suspect On Dirty won't fire for unbound control, but can't be sure (like I said, I never have/would see myself using it) for a control.
 
Hi Tim. We'll need to see how you're setting the colors, so we can get a hint as to why it is failing. Can you post the code, please? Thanks.


Is it similar to this?

First required control: cboLine1Workstation
Second required contrl: cboLineStopReason
Third required control: txtLineStopBegin (DateTime - - if it matters. This is equal to a click of label-turned-into-button that runs =Now() fwiw )

More info frmLineStop opens with ALL controls.Enabled = False & then turns on the first of the required controls w/ (actually - here is the entire Load code):

Code:
Private Sub Form_Load()

  Dim rs As DAO.Recordset
    If Not Trim(Me.OpenArgs & " ") = "" Then
        'See if record exists
        Set rs = Me.Recordset
        'MsgBox Me.OpenArgs
        rs.FindFirst "InspectionEvent_FK = " & CLng(Me.OpenArgs)
            If rs.NoMatch Then  'it does not exist so you need to create it
                DoCmd.GoToRecord acDataForm, Me.Name, acNewRec
                Me.InspectionEvent_FK = Me.OpenArgs
                Me.txtFinalProd_FK = intFinalProdID
                Me.NavigationButtons = False
                Me.cmdSaveLineStop.Enabled = False
                For Each ctl In Me.Controls
                    If ctl.Tag = "required" Or ctl.Tag = "secondary" Then
                    ctl.Enabled = False
                    End If
                Next
                Me.cboLine1Workstation.Enabled = True
                Me.cboLine1Workstation.BackColor = vbYellow
            End If
    Else
        If IsNull(Me.OpenArgs) Then
            Me.Filter = "LineStopBegin Is Not Null AND LineStopEnd Is Null"
            Me.FilterOn = True
            Me.NavigationButtons = True
        End If
    End If
End Sub

Selection is made by user in required control #1

Required control #1 On Dirty:

Code:
Private Sub cboLine1Workstation_Dirty(Cancel As Integer)
    If Dirty = True Then
    Me.cboLineStopReason.Enabled = True
    Me.cboLineStopReason.BackColor = vbYellow
    End If
End Sub

Required control #1 After Update:

Code:
Private Sub cboLine1Workstation_AfterUpdate()
    Me.cboLine1Workstation.BackColor = vbWhite
End Sub

Selection is made by user in required control #2.

On Dirty:

Code:
Private Sub cboLineStopReason_Dirty(Cancel As Integer)
    If Dirty = True Then
    Me.txtLineStopBegin.Enabled = True
    Me.txtLineStopBegin.BackColor = vbYellow
    Me.cmdLineStopBegin.Enabled = True
    End If
End Sub

2nd required control AfterUpdate:

Code:
Private Sub cboLineStopReason_AfterUpdate()
    Me.cboLineStopReason.BackColor = vbWhite
End Sub

3rd required control is now Enabled = True AND is BackColor = vbYellow

All other controls are Enabled = False including Save Button - at this point

Third required control AfterUpdate is:

Code:
Private Sub txtLineStopBegin_AfterUpdate()
    txtLineStopBegin.BackColor = vbWhite
    Me.cmdSaveLineStop.Enabled = True
End Sub

That is all
 
That is all
......is not true


3rd required field label is also a button with an On Click event which turns on Enabled =True
ALL remaining controls on form. Here is the code:

Code:
Private Sub cmdLineStopBegin_Click()
    Me.txtLineStopBegin = Now()
        For Each ctl In Me.Controls
            If ctl.Tag = "secondary" Then
            ctl.Enabled = True
            End If
            cmdSaveLineStop.Enabled = True
        Next
End Sub
 
........ or provide db.

Should open to frmMainMenu

Click "Inspections"

fill out w/ any info....form will tell you what is required .....values don't matter at this point

You are trying to click button "Line Stop"

frmLineStop is where all the action is - - - :-) LOL
 

Attachments

HOLD THE HORSES................

Light bulb went off - - -- -finally - - - -

I put the code on the Click event of the cmdButton of the 3rd required field et Voila.....


Why I did not see that at noon today - - -I do NOT know



................Thanks Everybody
 
Before you get too deep into this, have you considered the scenario where a prior control value is removed? I don't think I'd be using On Dirty event for a control. Before/After Update more likely. Maybe your last control is not bound? I suspect On Dirty won't fire for unbound control, but can't be sure (like I said, I never have/would see myself using it) for a control.

They're all bound Brother.....and I figured it out. It needed to go on the On Click event of the 3rd control. OTH - - -I DO appreciate your thought on Before/AfterUpdate vs Dirty - - - - I can see that now. Great point. Thank you. Considering.........
 
NP. Seems like you figured it out by your lonesome. I think I missed a point - that you are using buttons as labels. Interesting. Any particular reason? Need pictures or maybe keyboard shortcuts? Maybe it's because they are more intuitive for your application.
Anyway, happy programming to ya.
 
NP. Seems like you figured it out by your lonesome. I think I missed a point - that you are using buttons as labels. Interesting. Any particular reason? Need pictures or maybe keyboard shortcuts? Maybe it's because they are more intuitive for your application.
Anyway, happy programming to ya.

Aye to all of the above…and yeah… I am finally - actually - having fun with this :-)
 
Re: control BackColor

NP.I think I missed a point - that you are using buttons as labels. Interesting. Any particular reason?
Anyway, happy programming to ya.

I need a Start and Stop time. It seemed intuitive to me - b/c I like buttons- to turn the labels into buttons linked to text boxes to give the label/cmdButtons code On Click that puts a value (Me.Control) equals Now()
 

Attachments

  • LabelsAsButtons.JPG
    LabelsAsButtons.JPG
    54.7 KB · Views: 110
Before you get too deep into this, have you considered the scenario where a prior control value is removed? I don't think I'd be using On Dirty event for a control. Before/After Update more likely. Maybe your last control is not bound? I suspect On Dirty won't fire for unbound control, but can't be sure (like I said, I never have/would see myself using it) for a control.

When does the AfterUpdate event happen for a control on a form? Is it after data has been entered and the user clicks somewhere else?
 
Yes. When you try to move off a control, you get a beforeupdate event which you can cancel. If you don't cancel, and the update succeeds, you get an afterupdate.

eg it won't succeed if you enter bad data - if you have a date field, and enter a string, you will get a different error, which may or may not be handled.

I think normally changing the appearance of a selected control is done in the enter and exit events.
That way only one control is ever activated.
 

Users who are viewing this thread

Back
Top Bottom