Solved

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

Posted on 2012-12-26
11
602 Views
Last Modified: 2012-12-26
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
Comment
Question by:gigifarrow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
11 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 38721318
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
 

Author Comment

by:gigifarrow
ID: 38721621
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
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38721660
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 61

Expert Comment

by:mbizup
ID: 38721697
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
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 100 total points
ID: 38721736
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
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38721754
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
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38721778
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
 

Author Comment

by:gigifarrow
ID: 38721884
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
 
LVL 29

Assisted Solution

by:IrogSinta
IrogSinta earned 300 total points
ID: 38721974
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
 
LVL 30

Assisted Solution

by:hnasr
hnasr earned 100 total points
ID: 38722150
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
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38722256
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question