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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot setfocus() 1

Status
Not open for further replies.

lauritz

Programmer
Aug 20, 2002
27
AU
Hi,

I have a list box and several fill-ins on my form. I have populated the list box with data, and when the user clicks on it I want to populate the fill-ins with the list box data. In my listbox click event I grab the data I need, setfocus to one of my fill-ins and assign the fill in a value. This fires the change event of that fill-in which crashes with a run-time error 2110, can't move the focus to the control field cLocation. (the change event just populates the rest of the fill-ins). The field is enabled but won't accept focus. I am fairly new to access so am really struggling. I'd appreciate some help here.
Regards
 
It's not clear from your post whether or not you want the change event of the fill-in to fire. Hopefully not. . .using the events of one control to do things that trigger the events of other controls can quickly get out of hand.

To stop that second event from firing, put:

Application.Enableevents = False

early in the code of the first event. Be sure to reset it with:

Application.EnableEvents = True

at the end of your event code. Note that during development this can be a bit of a hassle whenever your code breaks after you have set .EnableEvents = False. You'll have to type "Application.EnableEvents = True" in the Immediate window before you can test your code again.

VBAjedi [swords]
 
Thanks for that. Maybe I am missing something...In the VBA editor when I type application. etc. I do not have the 'enableEvents' property in the select box. Simply typing it in generates a run time error. Is there some setup required for this? I am using Office 2002/WinXp.

Regards
Rod
 
Don't use the SetFocus method to populate a TextBox.
Use the .Value property of the textbox instead of the .Text

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PH. Sort of worked! My text boxes are now being populated with the data from the List Box, however I am now getting run-time error 2115. Any ideas?

Regards
Rod
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top