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

VBA - get value from control on a subform? 1

Status
Not open for further replies.

strider72

Programmer
Jan 11, 2004
3
US
I have a VBA macro that is giving me some trouble. Here's a pseudocode snippet:

Code:
    Dim x
    Dim strServiceDesc as String

    For Each x In <control &quot;desc&quot; on a continuous form subform>
        strServiceDesc = strServiceDesc & x & &quot;; &quot;
    Next x

I'm trying to look at a particular control on a subform to the current active form, and for each record showing on the subform, append the value of that control to a string that I will use later.

How do I refer to the control on the subform?

All help is appreciated. Thanks
Steve
 
Hi!

Assume this is a continous form, since you are saying &quot;for each record&quot;. I believe that would require you to loop thru the subforms records:

[tt]dim rs as dao.recordset
set rs=me!subformcontrolname.Form.Recordsetclone
if not rs.bof then
rs.movefirst
do while not rs.eof
' perform your assigning using the field name
s=s & & rs!fieldname
rs.movenext
loop
end if
set rs=nothing[/tt]

- typed not tested, you'd need a reference to the Microsoft DAO 3.# Library (in VBE Tools | References) perhps some errorchecking...

HTH Roy-Vidar
 
Worked like a charm, though I did not need the dao reference (&quot;dim rs as recordset&quot; worked fine).

Thanks much -- the response came so much faster than I expected I rescheduled the work and got it going a week early :)

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top