473,698 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query Where WHERE clause points to Current Row?

What is the syntax to refer to your current row in an SQL statement?

I am using the "Lookup Wizard" to build a query in a table. How do you
refer to the Current Row

For instance I have a Table Customers with City and State

and I have a Table Cities with a list of cities and States

I want the query for Row Source of Cities to be something like

SELECT Cities.ID, Cities.Name, Cities.State
FROM Cities
WHERE (((Cities.State )=THISROW.State ))

What would go in place of THISROW?

Thanks in Advance.

Nov 13 '05 #1
3 13275


ts******@gmail. com wrote:
What is the syntax to refer to your current row in an SQL statement?

I am using the "Lookup Wizard" to build a query in a table. How do you
refer to the Current Row

For instance I have a Table Customers with City and State

and I have a Table Cities with a list of cities and States

I want the query for Row Source of Cities to be something like

SELECT Cities.ID, Cities.Name, Cities.State
FROM Cities
WHERE (((Cities.State )=THISROW.State ))

What would go in place of THISROW?

Thanks in Advance.


I'm taking a guess about what you're trying to do.

tblCities
CityID Auto
CityName Text (Name is a Reserved Word)
CityState Text

1 Texarkana TX
2 Houston TX
3 Laredo TX
4 El Paso TX
5 Jennings LA

qryCityAndState :
SELECT (SELECT A.CityName & ', ' & A.CityState FROM tblCities AS A
WHERE A.CityID = tblCities.CityI D) As CityAndState FROM tblCities WHERE
tblCities.CityS tate = Forms!frmMain!c bxCityState.Val ue ORDER BY
tblCities.CityN ame;

! qryCityAndState (where cbxCityState.Va lue on frmMain = 'TX'):
El Paso, TX
Houston, TX
Laredo, TX
Texarkana, TX

The A.CityID = tblCities.CityI D forces the subquery (A) to use the
values from the current row. I hope this gets you close to what you're
looking for.

James A. Fortune

Nov 13 '05 #2
Thank you for your help. I'm sorry if I wasn't clear about what I was
doing.

The client has a City and a State Field, each of which contain ids that
are references to to other tables, When I am entering the data in the
datasheet I only want cities to show up that are in the Client's State
that has already been selected in the other field.

I am wondering about the statment

Forms!frmMain!c bxCityState.Val *ue

If I put that in it asks me to define it when I go to enter the data in
the datasheet. I assumed this was the name of the column in the current
record that is being edited? Or do I need to do this in a form?

Nov 13 '05 #3

ts******@gmail. com wrote:
Thank you for your help. I'm sorry if I wasn't clear about what I was
doing.

The client has a City and a State Field, each of which contain ids that
are references to to other tables, When I am entering the data in the
datasheet I only want cities to show up that are in the Client's State
that has already been selected in the other field.

I am wondering about the statment

Forms!frmMain!c bxCityState.Val *ue

If I put that in it asks me to define it when I go to enter the data in
the datasheet. I assumed this was the name of the column in the current
record that is being edited? Or do I need to do this in a form?


Your explanation helped. I hope by datasheet you mean a form in
datasheet view rather than a table field with a Lookup. By basing the
RecordSource of the Form on the table you are editing, you can use Form
Events to change the RowSource of a combobox in datasheet view
dynamically. That is, even though you're viewing the form in datasheet
mode, the event code behind the form is still available. Changing the
RowSource of a combobox based on existing values in the record is
typically done in the OnCurrent event. When the user moves to a new
record, code can look at the current value of a field by using the
control name with .Value for use in assigning a new RowSource to the
combobox control. Another possibility that becomes available is using
the AfterUpdate event of a combobox to change the RowSource of another
combobox dynamically. For instance, if 'TX' is chosen for the state,
the combobox for city can be set to return only cities that are in
Texas. Also note that you don't need the Forms!frmMain! part when
referring to a control on frmMain and the code is behind frmMain. When
you move to a record a THISROW is not needed. The value of the control
name grabs the value of the current record automatically. If the
OnCurrent event is used it will fire immediately on the first record
when the form is opened.

James A. Fortune

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3286
by: Steve | last post by:
I normally use MySQL with PHP, but I'm delving into connecting to Access with ODBC (for a database that I already have set up at work), and I'm running into a couple of errors. I'm just trying to do a simple query with two columns - one a name (VARCHAR), and one an integer column. First, if I add an ORDER BY clause, so the query looks like this: $sql = "select tblScores.FullName, sum(tblScores.Points) as TotalPoints from tblScores...
3
7874
by: Jonathan | last post by:
Hi all! For a match schedule I would like to find all possible combinations of teams playing home and away (without teams playing to themselves of course). I now the simple version works something like this: For a (very) simple table containing three rows like this: row 1: A
9
2760
by: Ed_No_Spam_Please_Weber | last post by:
Hello All & Thanks in advance for your help! Background: 1) tblT_Documents is the primary parent transaction table that has 10 fields and about 250,000 rows 2) There are 9 child tables with each having 3 fields each, their own PK; the FK back to the parent table; and the unique data for that table. There is a one to many relation between the parent and each of the 9 child rows. Each child table has between 100,000 and 300,000
0
1423
by: DH | last post by:
Hi. I'm not a SQL power user but can handle most simple queries. But I have no idea how to approach this problem...hopefully someone can point me in the right direction. I have a table which lists point numbers, bird species that was seen at each point, and the number of birds seen. So, if I saw 5 different kinds of birds at point #1, then there are 5 rows with '1' in the Point column and the bird name in the 'Species' column, and a 3rd...
5
3899
by: Bob Alston | last post by:
I have a where used utility that shows where any table or query is used - in a query, form or table. I would like some kind of diagram that shows these relations. I have some reports that require a lot of queries with query_totals and union queries to produce current day, current week, current month, current year to date and prior day, week month and year data.. these are Unioned together with appropriate keys to serve as input to a...
14
3492
by: Tina | last post by:
My employer tracks productivity/performance of clinicians (how much they bill) each week, its averages for the month, and the 6 months. These averages are compared to their expected productivity. However, the expectation changes - it may be 60% for a while, then change to 50%. Initially, I was averaging the expectation, along with the productivity, but what I'm being asked is to look at the average productivity/performance compared to...
8
7251
by: s_wadhwa | last post by:
SELECT DISTINCTROW "01C" AS dummy, Buildings.BuildingNumber, UCASE(Buildings.BuildingName) AS BuildingName, Buildings.MasterPlanCode, Buildings.UniformBuildingCode, Buildings.FunctionalCategoryCode, Buildings.OwnershipCode, Buildings.ConditionCode, Format$(,"0000000") AS dBasicGrossArea, Format$(,"0000000") AS dCoveredUnenclosedGrossArea, IIf(Month()>9,Month(),"0" & Month()) & Year() AS dDateOccupancy, Buildings.YearConstructed,...
5
4615
by: sara | last post by:
I have reports that run from a form where the user can choose a date range, or they run automatically for a week in the "Weekly Reports" option. I created 2 queries and 2 reports - one query uses the WeekEndDate to filter, and its associated report heading says "For the week Ending " & forms!frmPrintReports.getWeekEndDate. The other query selects the date range using "Between" and the 2 dates on the form. Its associated report header...
2
5744
by: jmarr02s | last post by:
I am creating a Pass Through Query. Here is my code: SELECT MDSDBA_CINTAKE.RECVDATE, MDSDBA_CINTAKE.CMPSRC, Count(MDSDBA_CINTAKE.CMPSRC) AS CountOfCMPSRC FROM MDSDBA_CINTAKE WHERE RECVDATE>=to_date( '01-09-2005','dd-mm-yyyy') AND RECVDATE<to_date( '01-10-2005','dd-mm-yyyy') AND CMPSRC IS NOT NULL GROUP BY CMPSRC;
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9027
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7725
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2329
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.