Change Background Color Double Click Event

crba724

New member
Local time
Today, 07:12
Joined
Jun 16, 2015
Messages
6
I feel like this should be a simple answer but I can't seem to find any previous forums that solve my specific question.

I am using a continuous form and would like my users to be able to change a field background color to a light red by double-clicking. The user would also be able to change it back to white by double-clicking again.

The code I am using (below) changes the field background color for all records. I need my code to only change the field color of the current record and cannot seem to find how to do that. The field name is [System_CurrentStatus].

Private Sub System_CurrentStatus_DblClick(Cancel As Integer)

If Me.System_CurrentStatus.Backcolor = vbWhite Then
Me.System_CurrentStatus.Backcolor = RGB(234, 154, 160)

ElseIf Me.System_CurrentStatus.Backcolor = RGB(234, 154, 160) Then
Me.System_CurrentStatus.Backcolor = vbwhite

End If
End Sub
 
Hello,

If you want to change the background color of the record that is on focus, it is not that simple. You will use the conditional formatting to do this. To simplify the operation, I changed your scenario a little bit. The user does not have the control of on/off for the background color here.

1. Create a Textbox in the Detail so that it covers the entire area. Name it as "Background".
2. From "Arrange", choose "Send Back" to move the control to the bottom layer so that all other fields are visible.
3. On the form's Current Event, write

Background = [ID]

[ID] is any field on the record that has a unique value.

4. Now select the Background control and choose "Conditional Formatting" on Format tab.
5. For the 1st condition, choose "Expression is" and enter
Background = [ID]
And select the appropriate color.
6. For the 2nd condition, use
Background <> [ID]
for condition and choose the color that is the same as the form's Details.
7. If the user directly click on the "Background" field, the cursor will stay there, which is not desirable. So, add On Enter Event for that field and move the focus to the first field.

Actually, adding the user option might be pretty complicated. I cannot think of any simple way off hand.

Hope my explanation is clear enough.

Shoji
 
Last edited:
crba724,

I didn't read your post carefully enough. My answer will change the color of the entire row, not a particular field. But all the clues you need are included in my answer. Unfortunately I have to go now. So, good luck and if you still have problems, I will get back to the issue later.

Shoji
 
Unfortunately, as mentioned, conditional formatting is not my goal in this scenario, nor is highlighting the entire row or column.

Previously we had been using an Excel spreadsheet to accomplish this work but the spreadsheet was enormous and caused a lot of issues so I converted it to an Access database. However, one of the features that was used in Excel was to change the fill color of the cell if it needed "special attention".

I want my users to have full control over the fields that get changed and having the whole row or column highlighted will not work.

It seems silly that I can apply the code I am using and have the entire column change but I cannot apply it to a specific record. Although, I am not a programmer and do not know a lot about writing code so there probably lies my frustration :o
 
It would serve your interests better to spend more care on reading shoji's suggestions.
 
As I appreciate the response, I will try another forum as my question was not answered.
 
Bye.

In that forum expend the effort to actually read and understand the answer that you failed to expend here, or else there too you won't find what you are looking for.
 
In a Continuous Form in Access, the only way to apply different formatting on different records (or rows) is by using Conditional Formatting.

If you do go to any other forum, it's wise to explore the solutions proposed rather than discredit it. It was your lack of understanding of what was proposed that led you to believe that it wouldn't work in your scenario. Conditional Formatting in Excel is not the same as Conditional Formatting in Access.

Always ask for clarity or better still give it a go before discrediting it.
 
I have a db someplace that I was able to change the color of the field that had the focus with conditional formatting, on a standard forum. Would that be different on a continues form? Or second did I misunderstand his question?
 
Yes it's different on a Continuous Form.

I was going to just try it on the db with a continues form, instead of asking, but I can't remember what db I did it on, but I remember who introduced me to conditional formatting. It was Big John Booty. I miss him. Also I wasn't sure I understood his question properly.

Now help me remember what db had the conditional formatting, and where its hiding. Even just the name of the db would help.:)
D7A
 
I am back, but crba724 may have gone.

I have an answer and am posting it anyway in case someone else might be interested.

You will have to add another field on the table that is the source of the continuous form. Since it seems to function as a flag, let's add a Yes/No field and call it "Flag".

You still need the conditional formatting, and in my first response, make the text control "Background" as small as you wish and place it anywhere appropriate.

Now, create a Dbl Click Event for that field and write

Code:
Private Sub Background_DblClick(Cancel As Integer)
    Me.Flag = Not Me.Flag
    Me.Requery
End Sub

Open the conditional formatting we created earlier, and change the line for "Expression is" to

[Flag] = True

Similarly, for the second condition, write

[Flag] = False

That is all. I have not tested this, so may need some adjustment.
crba724, you may still be around. Hope you will find this helpful.

Shoji
 

Users who are viewing this thread

Back
Top Bottom