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 to access text boxes from subforms

Status
Not open for further replies.

tmabrouk

Programmer
Aug 8, 2001
2
US

I have a subform within a main form and I want to access the information that is in a text box in the subform, but within the main form. i.e. I need to get the information being displayed in one of the text boxes on the subform, but I need it in one of the main form's modules.

Is there any VBA code to access this ?
 
in a textbox
=subformname.[form]!fieldname

in VBA
me.subformname.fieldname

 
That coding is fine if the subform has only one line of data, but what if there are several, such as am item form having a sales record subform with many records in it and a specific field from say the first or second record is needed in the main form or a new record or whatever?

That's been my problem here.
 
The faq was interesting but a coder would somehow have to develope code to test the number of rows returned in the subform (that I referenced above) and then define each column to pick out specific instances of data. I guess I'll do some research on that.

John
 
Yes, I didn't read your question thoroughly enough...

So, your subform is in datasheet view ?? If so, add code to the on current event of the sub-form. As you tab through the "rows", each column in the sub form is actually a textbox. Use the syntax outlined in my FAQ to "push" the data into the text boxes on the main form.

Heres an example from one of my DBs:

Code:
'Form fsfrRPDBSubAssy
Private Sub Form_Current()
 With Forms!frmRPDBSubAssy
        .txtComp.Value = Component
        .txtDesc2.Value = DESCRIPTION
        .txtAuth.Value = AUTHORIZATION
        .txtRepl_By.Value = Repl_By_2
        Select Case Expr2
            Case Is > 0
                Forms!frmRPDBSubAssy.cmdService.Visible = True
                .txtService.Value = Expr2
            Case Else
                Forms!frmRPDBSubAssy.cmdService.Visible = False
                .txtService.Value = 0
        End Select
       
    End With
Tyrone Lumley
augerinn@gte.net
 
Thanks, Tyrone, it looks like the answer for me. I won't get to this until next week. BTW, I checked out your web site, is there anything you don't do? (Hypothetical question)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top