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

Set listBox error statement

Status
Not open for further replies.

ActMod

Technical User
Aug 25, 2003
45
US
Following code results in an error that says "Method 'Item' of object 'Forms' failed". Error occurs on the "Set lstBox..." line.


Dim lstBox As ListBox
DoCmd.OpenForm "frmMktSgmtSelect", acNormal
Set lstBox = Forms!frmMktSgmtSelect!lstMktSgmts


Can someone explain why I am getting this error and how it can be addressed?

Thank you for any help.

Jim


 
The problem that you're experiencing is one of timing. You are trying to reference an object on the form that you've just opened, but you have not given the form a chance to open, instantiate all the controls and execute all the RecordSource commands.

My suggestion would be to create a Public Sub inside you main form where you would put the Set lstBox command, and then have the new form call that sub when the form is ready.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top