By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,696 Members | 1,607 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,696 IT Pros & Developers. It's quick & easy.

How to get a value from subform?

P: 36
Hi!
I want to get ProductName from a subform. Main form is "Customer Invoice" and the subform name is "Invoice Data". See the picture. Please help me if any one can do it. Thanks

Attached Images
File Type: jpg Corel.jpg (64.6 KB, 8336 views)
Jun 22 '15 #1
Share this Question
Share on Google+
4 Replies


Seth Schrock
Expert 2.5K+
P: 2,951
Please verify the name of the subform control by clicking on the subform, and then looking at the Name property in the Property window. Controls can't have spaces in their name. For now, I'll just replace the space with the underscore character. If you are referencing the ProductName in VBA from the Customer Invoice form, then you would use the following reference:
Expand|Select|Wrap|Line Numbers
  1. Me.Invoice_Data.Form.ProductName
If you are referencing it from another form in VBA or in the control source of a control on the main form, then you would use the following reference:
Expand|Select|Wrap|Line Numbers
  1. Forms![Customer Invoice].[Invoice_Data].Form.ProductName
See the following link for more details: Referring to Items on a Sub-Form.
Jun 22 '15 #2

zmbd
Expert Mod 5K+
P: 5,397
Aftab:
I don't understand what you are attempting here:

+ You have a line between two different fields one titled [product name] and the other [product id], are these the same thing?

+ You have a general invoice form and you are pulling the product from a line item to the header, which doesn't make sense. Are you storing this information in two different tables, If so, then Why?

+ You have not told us when/how/why the information should appear in the header of the invoice, this makes it difficult to provide any clear direction. Given that, one way I see to accomplish your goal is to use the on_current event of your subform so that when you select the line_item in the subform it transfers that information to the [product id] field.

+ Which version of Access/Office are you using?

Seth:
Actually Seth controls can have spaces in their names

HOWEVER,

The vba editor will replace those with underscores for event names and the name has to be enclosed in square brackets, or replaced with the underscore (works sometimes and not others :) ), as follows:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Unbound_text_Enter()
  2. Me.[Unbound text].Value = Me.[Unbound text].Name
  3. End Sub
For those that care :)
IMHO - spaces should be avoided at all times in Field Names, File Names, etc... so should any special characters and reserved names/tokens, exception is the underscore:

+List of reserved words in Access 2002 and in later versions of Access


+Reserved Words (Access 2013 custom web app)(for those working w/ sharepoint apps)

+ SQL Reserved Words

+ By far one of the most extensive listings of Problem names and reserved words in Access provide by Allen

Finally: From MS - Access reserved symbols:
The following symbols must not be used as part of a field name or as part of an object name:
. / * ; : ! # & - ? " ' $ %
(of course, one can often enclose the name in square brackets; however, best to avoid using these in the field/table/query/form-name)
Jun 22 '15 #3

P: 36
ZMBD!
I am using Access 2007. After update at control "ProductName" on Sbfrm i.e. "InvoiceData", I want to get ProductName from that control on Main form i.e. "Customer Invoice". Is that possible?
Jun 24 '15 #4

zmbd
Expert Mod 5K+
P: 5,397
use the afterupdate event of the record to transfer the data to the "parent" form's control.

"Parent" is a shortcut name much like "Me" is for the current form. Thus, a control on the main form named "textbox1" can be referred to from the child/subform as Me.Parent!Textbox1

Give that a try, if you get stuck, post your code and we'll help troubleshoot from there. :)
Jun 24 '15 #5

Post your reply

Sign in to post your reply or Sign up for a free account.