Cant get enter and exit functions to work properly

Brass Contributor

Using the Enter and Exit functions for text boxes, I can't get them to change color consistently.  Using tabs the color changes ok, but clicking around on different text boxes, the color does not always change.  I have looked at the code very closely and don't know what is going on.  Could someone help me resolve?

 

 

Private Sub txtPROGRAMManager_Enter()
txtPROGRAMManager.BackColor = RGB(206, 234, 235)
End Sub

Private Sub txtPROGRAMManager_Exit(ByVal Cancel As MSForms.ReturnBoolean)
txtPROGRAMManager.BackColor = vbWhite
End Sub

14 Replies

@guitar713 

Could you attach a small sample workbook demonstrating the problem (without sensitive data), or if that is not possible, make it available through OneDrive, Google Drive, Dropbox or similar?

@Hans Vogelaar here is a copy of the program,, whne you open it, click on the "ECO" button, and it will take you to the form.  If you click on the text boxes that I have changing color in the code, they do not resort back to the white color all the time, take a look and click around, see if you can see anything odd.  Thanks much.

@guitar713 

Thank you. I've clicked around hundreds of times, but the behavior was consistently correct.

I'm using Excel in Microsoft 365 version 2403 (32-bit) on Windows 11 Home version 23H2 (64-bit).

we are using 365 , 2402 version. very confused,, did you click aroung from frqme to frame as well,,, the area I am having issues with is switching between the "update type" box and the "requester" boxes, did you try that one?

@guitar713 

Yes, I did click from frame to frame, and more specifically from txtREQUESTERName to cmbUPDATEType and back, and it worked correctly every time.

But now it gets weird: when I reopened the workbook this morning, I did see the problem for some controls. I then closed and reopened the workbook, and it occurred for a different set of controls.

It seems that the Enter and Exit events do not always fire consistently.

One suggestion: add the line

 

txtDate_opened.BackColor = vbWhite

 

to fram_REQ_SPECIFIC_CHANGES_Enter and to fram_ENG_CHANGE_INFO_Exit.

I did that, it seems to work on those fields, but now I have an issue with going back and forth from "Requester" and "Updatetype"

@guitar713 

I see that too, intermittently. Sometimes, the txtREQUESTERName_Enter event doesn't occur when it should. You can probably mitigate it by adding _MouseDown event procedures, such as you already have for cmbUPDATETYPE:

Private Sub txtREQUESTERName_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    txtREQUESTERName.BackColor = RGB(206, 234, 235)
End Sub

Do the same for all such controls.

My bigger question is "WHY" does this happen. I thought these commands are supoosed to work in VBA, and are simple. Aren't we complicating the code by adding more code just to fix what looks like a "code" issue? any thoughts. Thanks.

@guitar713 

As far as I can tell, it is a bug in the way userforms raise events for controls in frames. The problem is mentioned in other forums.

@Hans Vogelaar 

 take a look at my changes,, now we have another issue,, I have the Urgency box as a dropdown, not only does it not populate, but nothing happens. the same with the Update Type,,, what do we do now? Thanks.

 

@guitar713 

This is really buggy - the MouseDown event apparently cancels the Change event.

Using the keyboard to select an item still works.

 

Is it really worth all this trouble to highlight the active control?

I really want to highlight the active controls. This makes a really nice form. In my head, we are dealing with one of the most popular software platforms out there, with these bugs, I can see why we don't use Microsoft to control rollercoasters and safety equipment. I'ld really like to find a solution for a good product for my company.
DO YOU HAVE ANY IDEAS TO GET THE COMBOBOX TO WORK WITH WHAT I WOULD LIKE TO DO?

@guitar713 

Sorry, no.

(No need to shout)