UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Highlight Command Button, Access 2016    
 
   
mike60smart
post Mar 26 2020, 03:31 PM
Post#1


UtterAccess VIP
Posts: 14,018
Joined: 6-June 05
From: Dunbar,Scotland


Hi Everyone

Edit*****
Please ignore this as I have gone a different route



I have a Continuous Subform with a Command Button that has the following On Click Event.

When the user Clicks the Command Button how can I make the background Colour of the button show as Red to indicate to the user which button they have Clicked?

The code is as follows:-

CODE
Private Sub cmdAddWE_Click()
10    On Error GoTo cmdAddWE_Click_Err

20    If Me.Dirty Then Me.Dirty = False
      
      Dim lngValue As Long

30    lngValue = MsgBox("Are you sure you have selected the Correct Record", vbYesNoCancel + vbQuestion, "Adding a New Error")
40    Select Case lngValue
         Case vbYes
50       DoCmd.OpenForm FormName:="frmWorkerErrorsSubform", _
        DataMode:=acFormEdit, _
        OpenArgs:=Me.DepartmentWorkerID
            
60          DoCmd.OpenForm "frmWorkerErrorsSubform", acNormal, "", "", , acNormal

70       Case vbNo
80          Me.cboWorker.SetFocus
90       Case vbCancel
100         Me.cboWorker.SetFocus
110   End Select

cmdAddWE_Click_Exit:
120       Exit Sub

cmdAddWE_Click_Err:
130       MsgBox Error$
140       Resume cmdAddWE_Click_Exit

End Sub


Any help appreciated

--------------------
Hope this helps?

Mike

Get happiness out of your work or you may never know what happiness is.

Go to the top of the page
 
RJD
post Mar 26 2020, 07:21 PM
Post#2


UtterAccess VIP
Posts: 10,566
Joined: 25-October 10
From: Gulf South USA


Hi Mike: I know you said to ignore this, but I already had a demo going, so will post it here.

Of course, on a continuous form with an unbound command button, any action against the command button itself will affect ALL of the command buttons you see (because they are, after all, only a single command button). So one (and I stress ONE) way to do this is to add a field to the underlying table and call it something like ColorIndicator. Then put that field in a control BEHIND the button, but a bit larger, so it shows. Then use conditional formatting to manipulate the color of the background control, and set up the other required maintenance. See the attached if you are interested.

There are surely to be other ways, perhaps involving a transparent button and a bound background control using CF, but when I saw your "never mind" comment I stopped there.

HTH
Joe
Attached File(s)
Attached File  HighlightCommandButton.zip ( 24.79K )Number of downloads: 11
 

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 
Larry Larsen
post Mar 27 2020, 03:57 AM
Post#3


UA Editor + Utterly Certified
Posts: 24,585
Joined: 26-August 02
From: Melton Mowbray,Leicestershire (U.K)


Hi Joe
QUOTE
but when I saw your "never mind" comment I stopped there.


Don't ever stop...

Your demo/examples are so helpful to those here at UA.. (that includes myself..)

They are delight to open up and see how simple things can be done use access, and your solutions are brilliant..

You attention to detail and speed are second only to theDBGuy.. (and you know how fast the big guy types..)
notworthy.gif thumbup.gif

--------------------
"Time...We have exactly the same number of hours per day that were given to Helen Keller, Pasteur, Michaelangelo, Mother Teresa, Leonardo da Vinci, Thomas Jefferson, and Albert Einstein"
H. Jackson Brown
Go to the top of the page
 
mike60smart
post Mar 27 2020, 06:34 AM
Post#4


UtterAccess VIP
Posts: 14,018
Joined: 6-June 05
From: Dunbar,Scotland


Hi Joe

Your solution is what I need but as always my Form structure is slightly Different

I have a Main Form with a Subform

Nested in the Subform is another Form which contains the Command Button I need to Highlight.

I currently have the following Code which includes the lines from your example.

CODE
Private Sub cmdAddWE_Click()
10    On Error GoTo cmdAddWE_Click_Err
20    CurrentDb.Execute "UPDATE tblDepartmentWorkers Set ColorIndicator = ''"
30    Me.Dirty = False
40    Me!ColorIndicator = "X"
50    Me.Dirty = False

       Dim lngValue As Long


60    lngValue = MsgBox("Are you sure you have selected the Correct Record", vbYesNoCancel + vbQuestion, "Adding a New Error")
70    Select Case lngValue
         Case vbYes
80       DoCmd.OpenForm FormName:="frmWorkerErrorsSubform", _
        DataMode:=acFormEdit, _
        OpenArgs:=Me.DepartmentWorkerID
90    CurrentDb.Execute "UPDATE tblDepartmentWorkers Set ColorIndicator = ''"
            
100         DoCmd.OpenForm "frmWorkerErrorsSubform", acNormal, "", "", , acNormal

110      Case vbNo
120         Me.cboWorker.SetFocus
130      Case vbCancel
140         Me.cboWorker.SetFocus
150   End Select


cmdAddWE_Click_Exit:
160       Exit Sub

cmdAddWE_Click_Err:
170       MsgBox Error$
180       Resume cmdAddWE_Click_Exit

End Sub


Private Sub ColourIndicator_GotFocus()

10        On Error GoTo ColourIndicator_GotFocus_Error
20    Me!cmdAddWE.SetFocus

          
30        On Error GoTo 0
40        Exit Sub

ColourIndicator_GotFocus_Error:

50        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure ColourIndicator_GotFocus, line " & Erl & "."

End Sub


When I click on the Command Button I get the following Error:-

Attached File  error.PNG ( 2.28K )Number of downloads: 1

--------------------
Hope this helps?

Mike

Get happiness out of your work or you may never know what happiness is.

Go to the top of the page
 
Larry Larsen
post Mar 27 2020, 07:10 AM
Post#5


UA Editor + Utterly Certified
Posts: 24,585
Joined: 26-August 02
From: Melton Mowbray,Leicestershire (U.K)


Hi Mike

Don't see Joe in the building at the moment, but done a simple reference command to control the viability of a control(Rectangle)..

Setup Main/subfrm/subsubfrm/control

On the Open event of the form to Hide the control
CODE
Me!subfrm.Form!SubSubfrm.Form!mybox.Visible = False



Event on the Main form (Combo Click) to show control..
CODE
Me!subfrm.Form!SubSubfrm.Form!mybox.Visible = True


Not sure if it helps you..
thumbup.gif

--------------------
"Time...We have exactly the same number of hours per day that were given to Helen Keller, Pasteur, Michaelangelo, Mother Teresa, Leonardo da Vinci, Thomas Jefferson, and Albert Einstein"
H. Jackson Brown
Go to the top of the page
 
RJD
post Mar 27 2020, 11:18 AM
Post#6


UtterAccess VIP
Posts: 10,566
Joined: 25-October 10
From: Gulf South USA


Larry: Thanks for stepping in on this while I was doing other things, and for your very kind words.

Mike: If you are still having issues, perhaps you could attach a db so we can all see your full configuration. Actually, I don't know where you are throwing the error, so it is hard to diagnose. In such cases I always start with a full ref to the subform rather than using Me. You know the db attachment drill.

HTH
Joe

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 
mike60smart
post Mar 27 2020, 12:42 PM
Post#7


UtterAccess VIP
Posts: 14,018
Joined: 6-June 05
From: Dunbar,Scotland


HI Joe

Here with a stripped down version

The Form that opens on the subform there is a Coloured Command Button "Work Errors" this is the Button that I need to go a different Colour.

Thanks for looking.

Attached File  Test.zip ( 141.35K )Number of downloads: 7

--------------------
Hope this helps?

Mike

Get happiness out of your work or you may never know what happiness is.

Go to the top of the page
 
RJD
post Mar 27 2020, 02:44 PM
Post#8


UtterAccess VIP
Posts: 10,566
Joined: 25-October 10
From: Gulf South USA


Hi Mike: Sorry, but I am now lost in your db. Here's how far I got ...

-I corrected the spellings of the ColourIndicator. I had used the US spelling of ColorIndicator (without the u), and you used that in the UPDATE queries, whereas you named the field ColourIndicator. That was the first error I found.

-I did not see a CF in the ColourIndicator control on the sub-subform. So I set that. I also adjusted the size and centered the X in the control.

-In some cases I used the entire form reference instead of Me!

This got me further along. But the form opening still errors and cancels. When I looked further, I got messages on forms that were misnamed. So, please check out again the OpenForm commands (why are there two of them?) and especially the openargs. Let's see if you can advance this a bit further along and let's see where we are.

HTH
Joe


Attached File(s)
Attached File  Test_UA_mike60smart_20200327_Rev1.zip ( 116.35K )Number of downloads: 10
 

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 
mike60smart
post Mar 27 2020, 02:58 PM
Post#9


UtterAccess VIP
Posts: 14,018
Joined: 6-June 05
From: Dunbar,Scotland


Hi Joe

Many Many thanks

I had not included the Table that the openArgs subform was based on

It now works as expected after adding this table

Many Many thanks yet again

cheers.gif

--------------------
Hope this helps?

Mike

Get happiness out of your work or you may never know what happiness is.

Go to the top of the page
 
RJD
post Mar 27 2020, 03:06 PM
Post#10


UtterAccess VIP
Posts: 10,566
Joined: 25-October 10
From: Gulf South USA


You are very welcome, Mike. Glad you got that sorted.

Continued success with your project.

Regards,
Joe

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 
mike60smart
post Mar 27 2020, 03:28 PM
Post#11


UtterAccess VIP
Posts: 14,018
Joined: 6-June 05
From: Dunbar,Scotland


Hi Joe

I spoke too soon

On trying to incorporate the process into my other database the Colour Indicator does not change Colour?

I have the following in the On Click of the button

CODE
Private Sub cmdAddWE_Click()
10    On Error GoTo cmdAddWE_Click_Err

       Dim lngValue As Long


20    lngValue = MsgBox("Are you sure you have selected the Correct Record", vbYesNoCancel + vbQuestion, "Adding a New Error")
30    Select Case lngValue
         Case vbYes
        
40             CurrentDb.Execute "UPDATE tblDepartmentWorkers Set ColourIndicator = ''"
50    Forms!frmCases!frmAddAuditorCasesSubform.Form!frmDepartmentWorkersSubform.Form.Dirty = False
60    Forms!frmCases!frmAddAuditorCasesSubform.Form!frmDepartmentWorkersSubform.Form!ColourIndicator = "X"
70    Forms!frmCases!frmAddAuditorCasesSubform.Form!frmDepartmentWorkersSubform.Form.Dirty = False

        
        
        
80       DoCmd.OpenForm FormName:="frmWorkerErrorsSubform", _
        DataMode:=acFormEdit, _
        OpenArgs:=Me!DepartmentWorkerID
        
90    'CurrentDb.Execute "UPDATE tblDepartmentWorkers Set ColourIndicator = ''"
            
100         DoCmd.OpenForm "frmWorkerErrorsSubform", acNormal, , , , acWindowNormal

110      Case vbNo
120         Forms!frmCases!frmAddAuditorCasesSubform.Form!frmDepartmentWorkersSubform.Form!cboWorker.SetFocus
130      Case vbCancel
140         Forms!frmCases!frmAddAuditorCasesSubform.Form!frmDepartmentWorkersSubform.Form!cboWorker.SetFocus
150   End Select


cmdAddWE_Click_Exit:
160       Exit Sub

cmdAddWE_Click_Err:
170       MsgBox Error$
180       Resume cmdAddWE_Click_Exit
End Sub


And On the ColourIndicator Got Focus I have this:-

CODE
Private Sub ColourIndicator_GotFocus()

10        On Error GoTo ColourIndicator_GotFocus_Error
20    Me!cmdAddWE.SetFocus

          
30        On Error GoTo 0
40        Exit Sub

ColourIndicator_GotFocus_Error:

50        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure ColourIndicator_GotFocus, line " & Erl & "."

End Sub


When I Click the Button I get the message warning and on clicking Yes it opens my Other Form correctly and then when I close this form it returns me to the Main Form.

At this point in your example the Colour Indicator should now be Red but on mine it does not change?

What am I missing?



--------------------
Hope this helps?

Mike

Get happiness out of your work or you may never know what happiness is.

Go to the top of the page
 
RJD
post Mar 27 2020, 03:58 PM
Post#12


UtterAccess VIP
Posts: 10,566
Joined: 25-October 10
From: Gulf South USA


Did you set the CF rule?

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 
mike60smart
post Mar 27 2020, 04:39 PM
Post#13


UtterAccess VIP
Posts: 14,018
Joined: 6-June 05
From: Dunbar,Scotland


Hi Joe

As simple as that - Many thanks

Also, if the user clicks the Command button again it pops up with the message"The Data Has Been Changed" ? Where has this been applied?

--------------------
Hope this helps?

Mike

Get happiness out of your work or you may never know what happiness is.

Go to the top of the page
 
RJD
post Mar 27 2020, 05:35 PM
Post#14


UtterAccess VIP
Posts: 10,566
Joined: 25-October 10
From: Gulf South USA


Hi: Well, it comes from this section of your code below. It is an error message - and you will have to track that down, and maybe put another message there, or trap the message number for other action.

cmdAddWE_Click_Err:
170 MsgBox Error$
180 Resume cmdAddWE_Click_Exit

If you change that line to ...

170 MsgBox Error$ & " This is it!"

... this should verify that this is the culprit.

HTH
Joe

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 
mike60smart
post Mar 28 2020, 06:55 AM
Post#15


UtterAccess VIP
Posts: 14,018
Joined: 6-June 05
From: Dunbar,Scotland


Hi Joe

Spot on Many thanks yet again
cheers.gif

--------------------
Hope this helps?

Mike

Get happiness out of your work or you may never know what happiness is.

Go to the top of the page
 
RJD
post Mar 28 2020, 07:09 AM
Post#16


UtterAccess VIP
Posts: 10,566
Joined: 25-October 10
From: Gulf South USA


thumbup.gif

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    5th July 2020 - 02:23 AM