PDA

View Full Version : Solved: Accidently selecting listbox entry on next Userform



Thymen
05-17-2006, 03:08 AM
Folks,

I have a userform with a textbox; if I doubleclick that textbox, another userform is loaded. But, then the entry of the listbox control at the location of the mousepointer gets selected, changing the original selection.

Is there a way to prevent this?

Thymen

BlueCactus
05-17-2006, 11:07 PM
A little hard to say without knowing more details. A couple of thoughts:

1. Try changing the screen position of the new form so that the controls don't overlay your textbox. Something like this:

Load NextForm
NextForm.StartUpPosition = 3
NextForm.Left = 100
NextForm.Top = 300
NextForm.Show

2. A long shot: Try setting ListBox.Enabled = False in the designer, and then using ListBox.Enabled = True at the end of Userform_Initialize(). The hope is that the click event is occuring before the form is initialized.

3. Is a double-click really required, or will a single click do the job?

Thymen
05-20-2006, 12:11 AM
BlueCactus,

I tried both options you suggested, but what i would like to know if there is some kind of standard command to empty the mouse-buffer. The application I am talking about gets used on many different screen sizes, option 1 is not suitable. And option 2 does not work, I even tries a one-sec delay procedure, but that does not work either
Thymen

MountainVogu
05-20-2006, 04:43 AM
You would be suprised at the non-sequential activity that seems to go on in Excel with VBA especially when using forms.

I have used a simple bit of code I found some time ago when I needed to stop processes from initiating that really shouldn't have started ! and it has not failed me yet.

Anyay bung this line in either the activate or initiate procedure of your form/s lauched by the textbox.

Application.Wait (Evaluate("=now()") + (0.15) / 86400)

0.15 your delay seconds
86400 seconds in a day

I normally bung set up a procedure and call in something like: hang 0.10. You may need to mess around with the smallest time you can pause for example .05 was too short on my system

Found it when I wanted waits of less than a second and trawled around the web for ages then found the gem ! To the original author "Karma Chief !"

Good luck :thumb

Thymen
05-22-2006, 12:00 AM
MountainVogue,

Works! Thanks a lot! Have quite a number of places where to use this!

Thymen