View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Jon Peltier Jon Peltier is offline
external usenet poster
 
Posts: 6,582
Default Refedit Retaining Focus

I avoid RefEdit events. In fact, here is some code I have left in one of my
charting userforms:

'''=============================================== =========================
'Private Sub refChtData_Change()
''' DON'T USE ANY RefEdit EVENTS!!
'End Sub

'Private Sub refChtData_Exit(ByVal Cancel As MSForms.ReturnBoolean)
''' DON'T USE ANY RefEdit EVENTS!!
'End Sub
'''=============================================== =========================

I simply rely on the user to select another control after they've changed
the contents of the RefEdit. I used to work with UserForm_MouseMove, but
that was tricky.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Pflugs" wrote in message
...
I am having this same problem with another userform I am making. I think
the
problem is with running events based on a refedit control.

Once the refedit value changes, I run an event to change the value of most
other controls in the form. Then, no matter what control I click on, the
form will freeze and crash, along with Excel.

Each refedit control includes an event that also sets the focus to
something
else as the value is changed. It still crashes. What would be a reason
for
this? I also tried AfterUpdate, and that doesn't seem to work.

Thanks,
Pflugs

"Jim Rech" wrote:

I've had this problem and found changing focus helps:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If ActiveControl.Name = "MyRefEdit" Then NamesListBox.SetFocus
End Sub

Doing it in the terminate event is too late I believe.

--
Jim
"Pflugs" wrote in message
...
|I created a userform that contains a RefEdit, several textboxes, and a
'Done'
| button. The form is initialized with the RefEdit as the focus. The
form
| also has a checkbox that when clicked modifies the width to reveal a
second
| set of controls.
|
| Sometimes when I click 'Done' to close the form, the RefEdit's
selection
| retains control. That is, the status bar says "Point" and the ants are
| marching around the selection. When this happens, the macro continues
to
run
| and Excel becomes confused and eventually crashes.
|
| I'm not sure why this is happening. I have even used
| "Application.CutCopyMode = False" on Terminate, and that doesn't seem
to
take
| care of all problems. I have also tried cleaning the code with Rob
Bovey's
| Code Cleaner. Any other suggestions?
|
| Thanks,
| Pflugs