Refer to a listbox on subform

whitedove

Registered User.
Local time
Today, 07:12
Joined
Jul 14, 2015
Messages
25
I am trying to refer to a multi select listbox property on a subform from the main form. Sounds simple but I guess it is not. It is a part of long code and query in vba. The listbox will gather all the selections in the listbox to feed it into a query.
I had the listbox on a tabbed control on the main form (tabbed control) and everything was working fine but the fields were so much on the tab which makes the page too long so I decided to add those fields on a subform. But I could not refer to the listbox on the subform to gather all the selections in the listbox

When the listbox was on the main form and everything was fine, this is the code I used
Code:
For Each varItem In Me.[FieldName].Itemselected
    strEmpl = strEmpl  & ",'" & Me.[FieldName].ItemData(varItem) _
    & "'"
When the listbox was moved to a subform and it did not work, this is the code I used
Code:
For Each varItem In Me!Subform1.Form![FieldName].Itemselected
    strEmpl = strEmpl  & ",'" & Me!Subform1.Form![FieldName].ItemData(varItem) _
    & "'"
When I run the second code I get the following message:
Run-time error '438':
Object doesn't support this property or method

So I am not sure if this is doable.

Any suggestions on modifying the second code?
 
uses the BUILDER, to get it exactly right.
its possible, you misspelled something in the path.
Me!Subform1.Form![FieldName]

AND
cycle thru the index, not ITEMSELECTED.
For varItem = 0 to me!Subform1.Form![FieldName].listcount -1
'use selected items
next
 
I double and triple checked the form name and field name and I think it is accurate. I did not get the second part of your answer

can you write the full code so I can try to apply it.

Thanks
 
I actually tried on purpose to mistype the subform name to see if I will get the same error but I did get a different error "Method or Data Member not found"

I do not want to change the whole code, I just want to change this line to get the value from the listbox on the subform while I am on the main form. Anyone?
Code:
For Each varItem In Me!Subform1.Form![FieldName].Itemselected
 
The Property name is ItemsSelected.
 
BTW Best refer to the listbox and other objects on the forms as "controls" because that is what they are called in Access. "Fields" are in tables, queries and recordsets.
 
Thank you so much. It looks like when I retyped the code I forgot the "S" in ItemsSelected.
Literally I spent like 3 hours and I did not catch that. Thank you so much!!
and thank you for the tip. I am kind of new to access so I will use the correct terms next time
 

Users who are viewing this thread

Back
Top Bottom