1

EDIT: nevermind I just created a new form, it looks worse but it's much easier

I have a form of orders and there are buttons and a subform on it. The form has a customer name that is given in the OpenArgs property when I open it from the Main form. The subform displays the orders that the user(the customer that see the page) did. When I make a condition that the customer name in the subform equals to the textbox that contains the customer name in the orders form, access

For example, the customer name is Matthew Jones (Me.OpenArgs="Matthew Jones") http://imageshack.us/photo/my-images/832/accesshelp.jpg/

Thank you and sorry if I had grammer mistakes

IdK
  • 31
  • 1
  • 2
  • 5

3 Answers3

2

I'm not sure if I understand what your actual question is.
This sentence looks like you posted the question without completing the sentence:

When I make a condition that the customer name in the subform equals to the textbox that contains the customer name in the orders form, access

If your question is how to get this to work, the solution is to write the query in the subform like this:

select *
from orders
where customer=[Forms]![OrderForm]![TextboxWithCustomerName]
Christian Specht
  • 35,843
  • 15
  • 128
  • 182
  • Thank you for the answer, I tried to do this but access didn't recognize it and opened a message box to get the value – IdK Jun 23 '11 at 16:15
  • This usually happens when you misspell the names, so you try to access something that doesn't exist. I just tried it on my machine (Access 2000): If I use the name of a textbox that doesn't exist, Access just loads the query without an error, but doesn't find anything. If I use the name of a form that doesn't exist, Access does exactly what you described (open a message box). So, you should double-check if the real name of your main form is exactly the same like the one you used in your query. – Christian Specht Jun 23 '11 at 16:21
  • I checked many times and I even use access 2010 that shows the possible names in a combo box, and the spell is OK I guess the problem is that the subform takes its recordsource before the "OnOpen" event, and I add the OpenArgs to the textbox there. – IdK Jun 23 '11 at 17:05
  • Okay, how about setting the RecordSource of the subform after that? `Set Me.Subform.RecordSource = "select * from orders where customer = " & Me.OpenArgs` – Christian Specht Jun 23 '11 at 18:09
1

You don't need to pass information to the subform via OpenArgs, because the subform is aware of the content of its parent form. You can access any data in the subform's parent form with Me.Parent. So, in the subform, if you wanted the CustomerName displayed in the parent form to be used in the subform, you'd use:

  Me.Parent!CustomerName

Keep in mind that you need to be sure that if CustomerName is a field in the parent form's Recordsource, it will be reliably accessible only if it's used as the ControlSource of a control on the parent form.

David-W-Fenton
  • 22,871
  • 4
  • 45
  • 58
0

You can use the LinkChildFields, LinkMasterFields properties of the subform control

  • In LinkMasterFields you must write
    the control name containing, in this case the customer's name.
  • In LinkChildFields you must write the field name of the orders list containing the customer's name.

The subform control makes the join between the 2 forms (main and child forms) and filter the subform acording the content of the main form.

Note that "subform control" is the container of the child form. The child form is a normal form that is loaded by a special control: the subform control.

mnieto
  • 3,744
  • 4
  • 21
  • 37