?
Solved

Referencing a field on a subform

Posted on 2011-03-16
4
Medium Priority
?
269 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 2000 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

764 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