Solved

Access SQL - Referring to a "parent" form

Posted on 2014-04-16
5
409 Views
Last Modified: 2014-04-16
Greetings!

See the very last "where" clause in my snippet.

The form will be called from one of two forms (either Job1 or Job2).

You will note that "Job1" is hardcoded into the "where" clause.

How do I change the "where" to simply refer to the parent form.....something like;
=forms!Parent![CustomerID]      (which does not work, of course).

SELECT tblCustomers.CustomerName, tblCustomers.CustomerID, [add1] & ", " & [add2] & ", " & [add3] & "," & [postcode] AS FullAddress, tblCustomers.GeneralComments, tblCustomers.EngineerComments, tblCustomers.RecommendedWorks, tblCustomers.CalloutCharge, tblCustomers.EngineersWorksCompleted
FROM tblCustomers
WHERE (((tblCustomers.CustomerID)=[forms]![job1]![CustomerID]));

Open in new window

0
Comment
Question by:Patrick O'Dea
  • 2
  • 2
5 Comments
 
LVL 35

Assisted Solution

by:Bembi
Bembi earned 150 total points
ID: 40005034
What is just to create a global variable and store the CustomerID there before you call the second form. This way you refer to the variable, not to the form.
0
 

Author Comment

by:Patrick O'Dea
ID: 40005140
Bembi,

Sounds like a good solution.  I created a global variable "CustomerCurrent".

But how to I refer the the global variable in the sql??
0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 350 total points
ID: 40005186
If the code is in the form, it's:

 Me.Parent![<controlName>]

Jim.
0
 
LVL 35

Expert Comment

by:Bembi
ID: 40005194
WHERE tblCustomers.CustomerID= myVariableName

or if your SQL statement is text...

"..... WHERE tblCustomers.CustomerID = " & myVariableName
0
 

Author Closing Comment

by:Patrick O'Dea
ID: 40005249
Thanks again Jim.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

920 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

15 Experts available now in Live!

Get 1:1 Help Now