Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox.Selected won't fire AfterUpdate

Status
Not open for further replies.

thatguy

Programmer
Aug 1, 2001
283
US
I have a bound form with a bunch of textboxes and a listbox.

After I requery the listbox, I set Listbox.Selected(0) = True, which, up until recently, caused the Listbox.AfterUpdate event to fire (which positions the record pointer and, voila, the selected record from the listbox is shown on the form).

This was working just fine until recently, but something happened -- I don't know what -- and now the AfterUpdate event doesn't fire when I set Selected(0) = True.

Is it supposed to fire or was it a fluke when it was firing? I've tried repairing the database to no avail. I'd hate to have a hidden flag on the form to show if the record pointer has moved, but if this is going to be so inconsistent, that seems the only option.

Thoughts?

Thanks
 
Most events are not fired by programmatic changes to controls.
 
Weird.. it was firing for awhile.. then just stopped suddenly.. *shrug*

I guess I'll have to add a hidden checkbox flag to the form -- unless there's some other way...?

Thanks
 
You can call the After Update event.
 
why not programatically call the afterupdate sub? Or better yet, create a custom funtion that is called?

Just a thought.

"If it's stupid but works, it isn't stupid."
-Murphy's Military Laws
 
I'd move the Listbox AfterUpdate event code into a procedure I'd call in the above event AND when setting the Selected property.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I actually move the record pointer in a sub (refHist) and the AfterUpdate calls that sub.

Originally, I was running the ListBox.Requery; Selected(0) = True; refHist; ... but then the AfterUpdate was getting called automatically and refHist was getting called twice, which threw up an error ("Update or CancelUpdate without AddNew or Edit") when the implicit save ran. So I removed the call to refHist from after the Selected(0) and things were fine.

Then, for no obvious reason, AfterUpdate stopped firing automatically and now I'm here.

I've added a hidden checkbox (chkRefd) to the form. I set it to False before the ListBox.Requery, then I set Selected. If chkRefd is still False after that then I call refHist. And in AfterUpdate I set chkRefd to True, as well. That ensures that refHist only gets called once. Kind of an ugly solution, IMHO, but it seems to work.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top