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!

Error when "Setting" ListBox

Status
Not open for further replies.

ActMod

Technical User
Aug 25, 2003
45
US
Can someone help me understand why I get the following error sometimes but not all the time when running the code that also follow:

Error: Method 'Item' of Object 'Forms" Failed

Code:
Dim lstBox as ListBox
DoCmd.OpenForm "frmMktSgmt", acNormal
Set lstBox = Forms!frmMktSgmt!lstMktSgmts

' lstBox is a ListBox on the Form named "frmMktSgmt"
' The Form "frmMktSgmt" opens with no problem but I get the error at the line Set lstBox = Forms! . . .

Thank you for any help.

Jim

 
Hi

A guess, It might be a 'timing' thing, Access will instigate the opening of the form in the docmd, code in the form which is being opening may be invoked and runs in parallel, ie after instigating the openning of the form Access continues with the next statement, which refers to the (open) forms collection and specifically to the form which has just been opened, maybe it is getting to the SET line before the form is fully opening and in the Forms Collection?

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Thank you for your response. I tried putting a break point on the "OpenForm" line, checked to ensure that the Form was open, and then proceeded with the code. I still received the error message. Does that rule out the potential timing issue?

Thanks again.

Jim
 
Hi

Sure does, like I said it was a guess, in the same spirit try

Set lstBox = Forms!frmMktSgmt.lstMktSgmts



Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Thanks much again. I don't know what is going on, but I opened an older version of the project and the macro started working again. It must be something else in my project that is messing up.

Thanks again for all your help.

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top