• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 609
  • Last Modified:

Trying to get check mark to disable when click and turn black, Once user makes mistake click to undo

Hello,

Experts. I have a database when you check it. It disables and turns black. Then I have a button that if that is a mistake you click on it to undo. but they both are not working because of the set focus is on the field to undo here is my code and here is the database.

To disable and turn black  I have after Update when you click the check mark:

Private Sub Defuel_AfterUpdate()
Me.Defuel.SetFocus
  If Me.Defuel.Value = True Then
    Me.Defuel.Enabled = False
    Me.Label4.BackColor = FFF200
  End If
End Sub

To reset I have on Click of a button :

 Private Sub Command221_Click()
  Me.Induction.Enabled = True
  Me.Label4.BackColor = vbWhite
  Me.Refresh
End Sub
bingo3.accdb
0
gigifarrow
Asked:
gigifarrow
  • 4
  • 2
  • 2
  • +2
3 Solutions
 
mbizupCommented:
Set the focus to some other control before disabling it:


Private Sub Defuel_AfterUpdate()
Me.Defuel.SetFocus
  If Me.Defuel.Value = True Then
   Me.SomeOtherControl.SetFocus
    Me.Defuel.Enabled = False
    Me.Label4.BackColor = FFF200
  End If
End Sub
0
 
gigifarrowAuthor Commented:
Okay thanks for your help
I did change it how you said so it looks like it is below.

1.when I hit reset it enables. But when I go to check it again. I get an error #2110 Can not set focus to Defuel .

 2. Also when I click the checks ony one turns black the others dont they just disable.


This is what Im doing on clicking the check boxes:

Private Sub Induction_AfterUpdate()
Me.Induction.SetFocus
  If Me.Induction.Value = True Then
    Me.Defuel.SetFocus
    Me.Induction.Enabled = False
    Me.Label4.BackColor = FFF200
  End If
  End Sub


Private Sub Defuel_AfterUpdate()
Me.Defuel.SetFocus
  If Me.Defuel.Value = True Then
  Me.Turret_ull.SetFocus
    Me.Defuel.Enabled = False
    Me.Label4.BackColor = FFF200
  End If
End Sub
This is what Im doing on reset:


Private Sub Command229_Click()
    Me.Induction.Enabled = True
    Me.Label7.BackColor = vbWhite
    Me.Refresh
End Sub
0
 
Jeffrey CoachmanCommented:
If Defuel is disabled, then you cannot set focus to it.

When doing things like this you have to control your code very tightly.

Consider moving all the "Set Properties" code to one sub, then make calls to this sub, from the needed events....

JeffCoachman
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
mbizupCommented:
I can't open your database at this time, but regarding the label color,  you may need to use a label that is not attached' to your check box for this kind of effect.
0
 
Jeffrey CoachmanCommented:
mbizup,
If it helps, ...Here is the code for the form

Option Compare Database

Private Sub Command221_Click()
  Me.Induction.Enabled = True
  Me.Label4.BackColor = vbWhite
  Me.Refresh
End Sub

Private Sub Command227_Click()
 Me.Defuel.Enabled = True
  Me.Label5.BackColor = vbWhite
  Me.Refresh
End Sub

Private Sub Command228_Click()
Me.Turret_ull.SetFocus
  If Me.Turret_ull.Value = True Then
    Me.Turret_ull.Enabled = False
    Me.Label6.BackColor = FFF200
  End If
End Sub

Private Sub Command229_Click()
Me.FuelCellRemoved.SetFocus
  If Me.Induction.Value = True Then
    Me.Induction.Enabled = False
    Me.Label7.BackColor = FFF200
  End If
End Sub

Private Sub Command230_Click()
Me.BFCSInstall.SetFocus
  If Me.BFCSInstall.Value = True Then
    Me.BFCSInstall.Enabled = False
    Me.Label9.BackColor = FFF200
  End If
End Sub

Private Sub Defuel_AfterUpdate()
Me.Defuel.SetFocus
  If Me.Defuel.Value = True Then
    Me.Defuel.Enabled = False
    Me.Label4.BackColor = FFF200
  End If
End Sub

Private Sub FuelCellRemoved_AfterUpdate()
Me.FuelCellRemoved.SetFocus
  If Me.FuelCellRemoved.Value = True Then
    Me.FuelCellRemoved.Enabled = False
    Me.Label7.BackColor = FFF200
  End If
End Sub

Private Sub Induction_AfterUpdate()
Me.Defuel.SetFocus
  If Me.Defuel.Value = True Then
    Me.Defuel.Enabled = False
    Me.Label4.BackColor = FFF200
  End If
End Sub


Private Sub Turret_ull_AfterUpdate()
Me.Turret_ull.SetFocus
  If Me.Turret_ull.Value = True Then
    Me.Turret_ull.Enabled = False
    Me.Label6.BackColor = FFF200
  End If
End Sub


Jeff
0
 
Jeffrey CoachmanCommented:
gigifarrow,

Not sure I follow your "Reset" logic...?

All your "reset" button does is enable the control again,  and set the color to white.
A true "reset" would check/un-check the control as well, because AFAICT, the properties are based on the control being true or false.
I can't see why you would want to reset the properties and not uncheck the control....
Am I missing something?

Also not sure why the refresh is needed either...
0
 
IrogSintaCommented:
When you open your form, would all the checkboxes be false or are some already checked?  If the latter, would the checked ones need to be disabled and have a black background?
0
 
gigifarrowAuthor Commented:
Thanks for all the help again experts. The reason for the check and uncheck


is if the user makes a mistake.
The user is going back and forth to each record everyday to add what they have done to the vehicle.

If they check it we dont wont them to accidentally uncheck it because the checks are a total of precentages.  If it is accidentally unchecked or checked all calculations will be off.

When they finish each step they want it to be disabled and to change you have to reset it.  They dont want them to go back and change it unless it is a mistake. When everything is black they know it is 100% finished

So if you reset it and uncheck we know it was done on purpose because that step had not been covered or they just accidentally hit it. I dont know the code to remove the check. I thought I would just enable and be able to uncheck it.

I hope that sounds clearer.


I am not an expert and there is probably a  better way that I could have done it.
0
 
IrogSintaCommented:
I modified your database a bit.  This version works with the first 6 checkboxes.  You just need to rename the rest of the checkboxes, labels, and reset buttons and add the corresponding procedures.  Don't forget to change the For Loop to the number of checkboxes.
bingo3.accdb
0
 
hnasrCommented:
Try this:
General sub to EnableDisable check boxes and color label.
Private Sub EnableDisable(ByVal c As Control)
    If c.Enabled Then
        c.Enabled = False
        c.Controls(0).BackColor = vbBlack
    Else
        c.Enabled = True
        c.Controls(0).BackColor = vbWhite
    End If
End Sub

'you call it from reset button by passing the check box control name.

Private Sub Command221_Click()
   Call EnableDisable(Me.Induction)
   ' no need to use caption if attached to check box control
End Sub

'Repeat with all reset buttons.

Open in new window

0
 
Jeffrey CoachmanCommented:
You accepted:
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_27977783.html#a38721736
That was just me posting the code for other experts (who may not have been able to open the db.

Please click the request Attention Link and have that post un-accepted.

Jeff
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 4
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now