Solved

Referencing a field on a subform

Posted on 2011-03-16
4
243 Views
Last Modified: 2012-05-11
See attached.

I have a header form (frmPackHeader) and a subform (frmPackDetail).
(One to many relationship)

On the header there is a button that activates the code below.
In particular note

WHERE (((tblPackDetail.PackDetailID)=[forms]![frmPackDetail]![PackDetailID]));

When I click on the button I am prompted to enter [forms]![frmPackDetail]![PackDetailID].  WHY ?
Surely the [forms]![frmPackDetail]![PackDetailID] field already has a value??  Why do I need to input it?


I hope the above is clear ...?
Private Sub Command7_Click()
DoCmd.OpenQuery "query1"
End Sub

Open in new window

Database7.accdb
0
Comment
Question by:Patrick O'Dea
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 500 total points
ID: 35152572
Change your query criteria to:

[forms]![frmPackHeader]![frmPackDetail].[Form].[PackDetailID]

mx
0
 
LVL 75
ID: 35152588
OR   [forms]![frmPackHeader]![PackDetailID]

depending on where you are trying to get the ID from ... Main for or Sub form (this would be Main form - first post is for SubForm)

mx
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 35152589
try this


WHERE (((tblPackDetail.PackDetailID)=[forms]![frmPackHeader]![frmPackDetail].[form]![PackDetailID]));
0
 

Author Closing Comment

by:Patrick O'Dea
ID: 35152597
Perfect.  Nice and easy!
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question