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!

Recognizing a ListBox

Status
Not open for further replies.

ActMod

Technical User
Aug 25, 2003
45
US
My macro does not recognize the ListBox (lstBox) that resides on a Form (frmMktSgmt)

I tried the following two codes with two different error messages:

CODE 1:
Dim lstBox as ListBox
DoCmd.OpenForm "frmMktSgmt", acNormal
Set lstBox = Forms("frmMktSgmt")("lstMktSgmts")

'Form opens in normal view but I get the following error on the "Set lstBox = . . ." line:
"Method 'Item' of Object 'Forms' Failed"


CODE2:
DoCmd.OpenForm "frmMktSgmtSelect", acDesign
Set lstBox = Forms("frmMktSgmt")("lstMktSgmts")
DoCmd.OpenForm "frmMktSgmt", acNormal
NumList = lstBox.ListCount

'Form opens in Design view and the Set lstBox line seems to work. But when I open the Form in Normal view so I can act on the ListBox, the "lstBox" properties appear to vanish. I get the following error on the "NumList = ..." line:
"The expression you entered refers to an object that is closed or doesn't exist".


Any help with fixing one of the above errors would be greatly appreciated.

Jim
 
I can't see what you're trying to do in CODE1

But in CODE2 I think all you need is


CODE2:
Code:
DoCmd.OpenForm "frmMktSgmt", acNormal
NumList = Forms!frmMktSgmt!lstMktSgmts.ListCount



'ope-that-'elps.




G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
Thank you for your suggestion. Unfortunately, I am getting the same error message. Do you see any problem with my following line?
Set lstBox = Forms("frmMktSgmt")("lstMktSgmts")

I also tried:
Set lstBox = Forms!frmMktSgmt!lstMktSgmts

Thanks again.
 
I see LOTS and LOTS of problems with you using the word SET in any context other than attributing object variables to an instance of an object ( Which - as far as I cn see - you are NOT trying to do. )



Why don't you use the format I set out in the first post ?





G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top