Solved

Referencing a field on a subform

Posted on 2011-03-16
4
237 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 119

Expert Comment

by:Rey Obrero
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

867 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now