Printable Version of Topic

Click here to view this topic in its original format

UtterAccess Forums _ Access Forms _ Syntax For Referencing A Textbox On A Subform

Posted by: projecttoday Dec 7 2017, 12:18 AM

Does anybody know the correct syntax for referencing a textbox on a subform in a main form? The textbox in question is in the footer section of the subform. I tried Me.Subformname.Form.Controlname but that didn't work.

The attached db is the one where this came up in another thread. Form2 contains 2 subforms, 1 for debits. 1 for credits. We are trying to calculate the balance of total debits minus total credits. I'm using Dsum's but I'd rather reference the subforms.

 subformtest.zip ( 41.09K ): 7
 

Posted by: HairyBob Dec 7 2017, 04:14 AM

Hi Robert,

Try:

CODE
Me.[Receipts Form].Form.txtDrSum


And:

CODE
Me.[Payment Form].Form.txtCrSum


Where [Receipt Form] and [Payment Form] are the Sub Control names.

HTH...

Hairy.

Posted by: projecttoday Dec 7 2017, 07:42 AM

As I stated in my post, I've already tried that. If you've done it this way and it works, then please post it.

Posted by: BruceM Dec 7 2017, 07:57 AM

If referencing it by using an expression in the text box Control Source the Me syntax won't work since that is VBA only. This worked for me as Control Source expressions:

=[Forms]![Form2]![Receipts Form].[Form]![txtDrSum]
=[Forms]![Form2]![Payment Form].[Form]![txtCrSum]

If those text boxes are named txtDrTotal and txtCrTotal you can have another text box to sum those:

=[txtDrTotal] + [txtCrTotal]

I assume you are not trying to use VBA, since I don't see any code in the sample database. If you are trying to use VBA, more information is needed.

Posted by: Scott McDaniel Dec 7 2017, 08:00 AM

You can use this:

Me.FormFooter.Controls("txtcrsum")

Or the full reference to the form:

Forms!YourForm.FormFooter.Controls("txtcrsum")

Posted by: mike60smart Dec 7 2017, 09:04 AM

Hi Robert

See the attached

 subformtest.zip ( 51.56K ): 7

Posted by: BruceM Dec 7 2017, 09:22 AM

Yes, that is the same as my suggestion, except I mistakenly showed addition rather than subtraction with credits and debits.

Posted by: projecttoday Dec 7 2017, 09:25 AM

Thanks to all who posted. The solution proposed by Bruce works. (I have used this in the past, I just couldn't remember it.) Thanks to all who posted.

Posted by: HairyBob Dec 7 2017, 10:04 AM

Hi Robert,

Looks like Mike & Bruce beat me to it; however, here's what I did to test it (see attachment). Apologies for not posting the attachment in the first place.

Regards,

Hairy.

 subformtest2.zip ( 49.1K ): 1
 

Posted by: BruceM Dec 7 2017, 10:10 AM

Glad to hear it. Good luck with the project.

Posted by: projecttoday Dec 7 2017, 10:58 AM

Thanks, Hairy.