Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

Referencing a field on a subform

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
Patrick O'Dea
Asked:
Patrick O'Dea
  • 2
1 Solution
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Change your query criteria to:

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

mx
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
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
 
Rey Obrero (Capricorn1)Commented:
try this


WHERE (((tblPackDetail.PackDetailID)=[forms]![frmPackHeader]![frmPackDetail].[form]![PackDetailID]));
0
 
Patrick O'DeaAuthor Commented:
Perfect.  Nice and easy!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now