Help with Subforms

A

Ayo

I have a form with a textbox and a subform. I want the subform to be filtered
based on what the value in the textbox is. I have a table with vendors,
invoices and dates. For each vendor in the textbox, I want the subform to
contain the invoices and date reated to the vendor.
How can I accomplish this?
Thank you
 
T

Tim Johnson

If the textbox is unbound, or there is not a relationship between the
table/query its bound to and the table/query your subform is based on, you
will need an event to trigger the updates in the subform. This can most
easily be accomplished with a button's OnClick event in the main form, or
using the main form's OnCurrent event, depending on your specific
configuration.

The vba code would look something like this (the braces {/} will be used to
describe the names in your specific database, and should be removed from the
code once you have entered the appropriate names):

'//This Code may paste into more than one line, if so, make sure that it
ends up on one line only
me.{SubformName}.form.recordsource = "Select {TableName}.{Vendor},
{TableName}.{Invoice}, {TableName}.{Date} From {TableName}
Where(({TableName}.{Vendor}) = '" & me.{TextboxName} & "')"

If your textbox is bound, and the field it is bound to is part of a
relationship with your subform's data source, then the method is much simpler:

In the Properties window for your subfrom, click on the "Data" tab. Select
the related fields for the Link Master Fields and the Link Child Fields.
 
R

Rick Brandt

Ayo said:
I have a form with a textbox and a subform. I want the subform to be
filtered based on what the value in the textbox is. I have a table
with vendors, invoices and dates. For each vendor in the textbox, I
want the subform to contain the invoices and date reated to the
vendor.
How can I accomplish this?
Thank you

That is what the MasterLink and ChildLink properties of the subform control do
for you. Enter the name of the TextBox in the MasterLink property and the name
of the matching field from the subform into the ChildLink property.
 

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

Similar Threads


Top