form-subform transfer

J

JohnE

I have a main form (FormA). On it is a tab control with a
subform on it (SubformA). In the subform is a button that
opens a popup form (PopA) with all the states to select
from. On the popup form is a button that is to transfer
the selected states from the popup form to a textbox on
the subform. I keep getting an error of recognition of
the field. Here is what I have. It hangs on the last
line.

Dim varItem As Variant, strStates As String
For Each varItem In Me.lstStates.ItemsSelected
If strStates = "" Then
strStates = Me.lstStates.ItemData(varItem)
Else
strStates = strStates & vbCrLf &
Me.lstStates.ItemData(varItem)
End If
Next

Form![SubformA].[States] = strStates

Anyone see what I'm missing? I have changed around and
added the main form info but is still stops at the last
line.

Thanks in advance for any assistance.
*** John
 
A

Allen Browne

Subforms are not part of the forms collection.
You must refer to it through the main form.

Try:
Forms[FormA]![SubformA].Form![States] = strStates

For an explanation (including the .Form bit) see:
Referring to Controls on a Subform
at:
http://allenbrowne.com/casu-04.html

BTW, if the above does not work, open the main form in design view,
right-click the subform control and choose Properties. The Name of the
subform control can be different from its SourceObject (the name of the form
it contains.)
 
R

Ron Weiner

Try

Forms!FormA.NameOfTheSubformControlForSubformAOnTheTabControlOfFormA.States
= strstates

Ron W
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top