MS Access SQL - No Current Record Error

%3CLINGO-SUB%20id%3D%22lingo-sub-2909009%22%20slang%3D%22en-US%22%3EMS%20Access%20SQL%20-%20No%20Current%20Record%20Error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2909009%22%20slang%3D%22en-US%22%3E%3CDIV%20class%3D%22%22%3E%3CP%20class%3D%22%22%3EHi%3C%2FP%3E%3CP%3EI%20am%20getting%20this%20error%20when%20I%20run%20a%20query%20below%20query%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESELECT%20*%2C%3CBR%20%2F%3E(SELECT%20STDEV(LOG_PRICE_CHANGE)%3CBR%20%2F%3EFROM%20QRY_LOG_PRICE_CHANGES%20AS%20T1%3CBR%20%2F%3EWHERE%20T1.UNDERLYING_SYMBOL%20%3D%20QRY_LOG_PRICE_CHANGES.UNDERLYING_SYMBOL%20AND%3CBR%20%2F%3EQRY_LOG_PRICE_CHANGES.ROW_NUMBER-T1.ROW_NUMBER%20BETWEEN%200%20AND%2020)%20AS%20STD_DEV%3CBR%20%2F%3EFROM%20QRY_LOG_PRICE_CHANGES%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere%20are%20the%20steps%20I%20have%20taken%20so%20far%20in%20troubleshooting%20this%20issue%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1.%20I%20ran%20QRY_LOG_PRICE_CHANGES%20and%20it%20ran%20with%20no%20issues.%20This%20means%20this%20query%20is%20correct.%20The%20query%20is%20slow%20though.%20Could%20that%20be%20an%20issue%3F%20Does%20Access%20have%20a%20timeout%20feature%20that%20I%20am%20not%20aware%20of%3F%20It%20probably%20takes%202%20minutes%20max%20to%20run.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E2.%20If%20I%20change%20QRY_LOG_PRICE_CHANGES%20to%20TBL_LOG_PRICE_CHANGES%20then%20noted%20query%20runs%20without%20any%20issues.%20This%20means%20that%20the%20noted%20query%20will%20process%20the%20data%20that%20is%20found%20in%20QRY_LOG_PRICE_CHANGES%20so%20there%20are%20no%20data%20issues%20or%20incompatible%20header%20issues.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E3.%20The%20test%20database%20is%20about%201.6%20GB.%20Access%20has%20a%202%20GB%20limit%20(i%20think).%20I%20created%20a%20new%20temp%20DB%20and%20had%20a%20linked%20table%20created%20that%20displayed%20the%20raw%20data%20from%20the%20test%20database%20in%20the%20temp%20database%20I%20created.%20I%20then%20copied%20the%20two%20queries%20(QRY_LOG_PRICE_CHANGES%20and%20above%20noted%20query)%20into%20the%20temp%20DB.%20I%20still%20get%20the%20same%20error%20message.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E4.%20I%20have%20checked%20online%20for%20this%20error%20and%20it%20makes%20references%20to%20SYSDATA%20folder.%20I%20checked%20my%20computer%20and%20I%20don't%20even%20have%20this%20folder.%20Here%20is%20the%20Microsoft%20literature%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Ftopic%2Frun-time-error-3021-no-current-record-1265be01-5850-c5e3-5d10-f90cf122818c%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Ftopic%2Frun-time-error-3021-no-current-record-1265be01-5850-c5e3-5d10-f90cf122818c%3C%2FA%3E%3C%2FP%3E%3C%2FDIV%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENot%20sure%20if%20this%20is%20related%20or%20not.%20Obviously%2C%20Microsoft%20says%20it%20is%20so%20it%20probably%20is.%20I%20just%20don't%20understand%20why%20only%20this%20query%20is%20giving%20me%20a%20hard%20time.%20I%20have%20multiple%20queries%20that%20are%20running%20off%20the%20same%20main%20table%20etc%20and%20no%20issues%20with%20those.%20It%20is%20just%20this%20one%20query%20that%20is%20giving%20me%20a%20problem.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E5.%20Not%20sure%20if%20this%20is%20related%20or%20not.%20I%20always%20use%20alias%20of%20the%20form%20TX%20where%20X%20%3D%201%2C2%2C3%2C%20etc.%20I%20was%20not%20able%20to%20create%20the%20second%20alias%20so%20it%20is%20left%20as%20is.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E6.%20Running%20a%20simple%20query%20works%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESELECT%20*%3CBR%20%2F%3EFROM%20qry_Log_Price_Changes%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20really%20stumped%20here.%20Not%20sure%20what%20else%20to%20do.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDoes%20anyone%20know%20what%20is%20going%20on%20here%3F%3C%2FP%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2909009%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAccess%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2911678%22%20slang%3D%22en-US%22%3ERe%3A%20MS%20Access%20SQL%20-%20No%20Current%20Record%20Error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2911678%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F765012%22%20target%3D%22_blank%22%3E%40manny213%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%3C%2FP%3E%3CP%3EIs%20anyone%20able%20to%20help%20me%20with%20this%3F%3C%2FP%3E%3CP%3EThank%20you%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2912598%22%20slang%3D%22en-US%22%3ERe%3A%20MS%20Access%20SQL%20-%20No%20Current%20Record%20Error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2912598%22%20slang%3D%22en-US%22%3E%3CP%3EDoes%20the%20subquery%20work%20as%20a%20standalone%20query%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20can%20find%20various%20timeout%20settings%20in%20Access%20options..%20Client%20Settings....Advanced%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2914437%22%20slang%3D%22en-US%22%3ERe%3A%20MS%20Access%20SQL%20-%20No%20Current%20Record%20Error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2914437%22%20slang%3D%22en-US%22%3EThanks%20for%20the%20reply.%3CBR%20%2F%3E%3CBR%20%2F%3EYes%20the%20base%20query%20QRY_LOG_PRICE_CHANGES%20runs%20fine%20on%20its%20own.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20took%20a%20look%20at%20the%20Client%20Settings...Advanced%20options.%20There%20are%205%20settings.%20Which%20one%20would%20you%20suggest%20I%20look%20at%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2914485%22%20slang%3D%22en-US%22%3ERe%3A%20MS%20Access%20SQL%20-%20No%20Current%20Record%20Error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2914485%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F765012%22%20target%3D%22_blank%22%3E%40manny213%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThat%20wasn't%20my%20question.%26nbsp%3BThis%20is%20the%20subquery%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual-basic%22%3E%3CCODE%3ESELECT%20STDEV(LOG_PRICE_CHANGE)%0AFROM%20QRY_LOG_PRICE_CHANGES%20AS%20T1%0AWHERE%20T1.UNDERLYING_SYMBOL%20%3D%20QRY_LOG_PRICE_CHANGES.UNDERLYING_SYMBOL%20AND%0AQRY_LOG_PRICE_CHANGES.ROW_NUMBER-T1.ROW_NUMBER%20BETWEEN%200%20AND%2020%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDoes%20that%20run%20as%20a%20standalone%20query%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThese%20are%20my%20settings%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22isladogs_0-1635864211258.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F323178i445269C4AE03D410%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22isladogs_0-1635864211258.png%22%20alt%3D%22isladogs_0-1635864211258.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHow%20do%20yours%20differ%20from%20those%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2915048%22%20slang%3D%22en-US%22%3ERe%3A%20MS%20Access%20SQL%20-%20No%20Current%20Record%20Error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2915048%22%20slang%3D%22en-US%22%3ESorry%20about%20that%20confusion.%3CBR%20%2F%3ENo%2C%20that%20subquery%20will%20not%20run.%20It%20is%20saying%20%22QRY_LOG_PRICE_CHANGES.UNDERLYING_SYMBOL%22%20is%20a%20parameter%20and%20wants%20a%20value.%3CBR%20%2F%3E%3CBR%20%2F%3EMy%20settings%20are%20the%20same%20as%20yours.%3C%2FLINGO-BODY%3E
Occasional Contributor

Hi

I am getting this error when I run a query below query:

 

SELECT *,
(SELECT STDEV(LOG_PRICE_CHANGE)
FROM QRY_LOG_PRICE_CHANGES AS T1
WHERE T1.UNDERLYING_SYMBOL = QRY_LOG_PRICE_CHANGES.UNDERLYING_SYMBOL AND
QRY_LOG_PRICE_CHANGES.ROW_NUMBER-T1.ROW_NUMBER BETWEEN 0 AND 20) AS STD_DEV
FROM QRY_LOG_PRICE_CHANGES

 

Here are the steps I have taken so far in troubleshooting this issue:

 

1. I ran QRY_LOG_PRICE_CHANGES and it ran with no issues. This means this query is correct. The query is slow though. Could that be an issue? Does Access have a timeout feature that I am not aware of? It probably takes 2 minutes max to run.

 

2. If I change QRY_LOG_PRICE_CHANGES to TBL_LOG_PRICE_CHANGES then noted query runs without any issues. This means that the noted query will process the data that is found in QRY_LOG_PRICE_CHANGES so there are no data issues or incompatible header issues.

 

3. The test database is about 1.6 GB. Access has a 2 GB limit (i think). I created a new temp DB and had a linked table created that displayed the raw data from the test database in the temp database I created. I then copied the two queries (QRY_LOG_PRICE_CHANGES and above noted query) into the temp DB. I still get the same error message.

 

4. I have checked online for this error and it makes references to SYSDATA folder. I checked my computer and I don't even have this folder. Here is the Microsoft literature:

 

 

Not sure if this is related or not. Obviously, Microsoft says it is so it probably is. I just don't understand why only this query is giving me a hard time. I have multiple queries that are running off the same main table etc and no issues with those. It is just this one query that is giving me a problem.

 

5. Not sure if this is related or not. I always use alias of the form TX where X = 1,2,3, etc. I was not able to create the second alias so it is left as is.

 

6. Running a simple query works:

 

SELECT *
FROM qry_Log_Price_Changes;

 

I am really stumped here. Not sure what else to do.

 

Does anyone know what is going on here?

15 Replies

@manny213 

Hi

Is anyone able to help me with this?

Thank you

Does the subquery work as a standalone query?

 

You can find various timeout settings in Access options.. Client Settings....Advanced

 

 

Thanks for the reply.

Yes the base query QRY_LOG_PRICE_CHANGES runs fine on its own.

I took a look at the Client Settings...Advanced options. There are 5 settings. Which one would you suggest I look at?

@manny213 

That wasn't my question. This is the subquery:

SELECT STDEV(LOG_PRICE_CHANGE)
FROM QRY_LOG_PRICE_CHANGES AS T1
WHERE T1.UNDERLYING_SYMBOL = QRY_LOG_PRICE_CHANGES.UNDERLYING_SYMBOL AND
QRY_LOG_PRICE_CHANGES.ROW_NUMBER-T1.ROW_NUMBER BETWEEN 0 AND 20

 

Does that run as a standalone query?

 

These are my settings:

isladogs_0-1635864211258.png

 

How do yours differ from those?

 

Sorry about that confusion.
No, that subquery will not run. It is saying "QRY_LOG_PRICE_CHANGES.UNDERLYING_SYMBOL" is a parameter and wants a value.

My settings are the same as yours.
OK. You need to ensure that works as a standalone query before you can use it as a subquery.
Try inserting a value that you know exists and then see if it works as standalone / subquery.
If so, you need to find a way of adding the parameter to the query
a few things...
1. i re-ran the subquery and put in random values for the two parameters. it ran without any errors but the value it produced was NULL.

2. secondly, that subquery you mentioned definitely does work. one of the things i tried when I was troubleshooting this was try the below query:

SELECT T2.UNDERLYING_SYMBOL, T2.QUOTE_DATE, (SELECT STDEV(LOG_PRICE_CHANGE)
FROM TBL_LOG_PRICE_CHANGES AS T1
WHERE T1.UNDERLYING_SYMBOL = T2.UNDERLYING_SYMBOL AND
T2.ROW_NUMBER-T1.ROW_NUMBER BETWEEN 0 AND 20) AS STD_DEV_21
FROM TBL_LOG_PRICE_CHANGES AS T2;

noticed that TBL_LOG_PRICE_CHANGES is used and not QRY_LOG_PRICE_CHANGES

QRY_LOG_PRICE_CHANGES runs fine on its own

for some unknown reason, the query doesn't like it when qry is used in the FROM clause
I ran the query again and now I am getting a different error. I am getting "Invalid value to function"

SELECT T2.UNDERLYING_SYMBOL, T2.QUOTE_DATE, (SELECT STDEV(LOG_PRICE_CHANGE)
FROM TBL_LOG_PRICE_CHANGES AS T1
WHERE T1.UNDERLYING_SYMBOL = T2.UNDERLYING_SYMBOL AND
T2.ROW_NUMBER-T1.ROW_NUMBER BETWEEN 0 AND 20) AS STD_DEV_21
FROM QRY_LOG_PRICE_CHANGES AS T2;

If I run the below query then no issues:

SELECT T2.UNDERLYING_SYMBOL, T2.QUOTE_DATE, (SELECT STDEV(LOG_PRICE_CHANGE)
FROM TBL_LOG_PRICE_CHANGES AS T1
WHERE T1.UNDERLYING_SYMBOL = T2.UNDERLYING_SYMBOL AND
T2.ROW_NUMBER-T1.ROW_NUMBER BETWEEN 0 AND 20) AS STD_DEV_21
FROM TBL_LOG_PRICE_CHANGES AS T2;

Only difference is the FROM part. The first is referencing a query and the second is referencing a table

Any idea on what is going on here? So strange...
Its difficult to know based on the info you've supplied.
Can you upload a cut down version of your database with all relevant items?
Remove or change any confidential data

@isladogs 

good idea.  thank you for suggesting this.

 

i have attached a sample db. 

 

========

qry_v1_alias

========

gives "The specified field 'T2.Store' could refer to more than one table listed in the FROM clause of your SQL statement" error
not sure why it is giving this error.

this is a problem b/c I don't know why it doesn't like alias.  To be honest this is a minor problem.  if I can't use alias then no big deal.

 

==========

qry_v1_no_alias

==========

gives "No Current Record" error

this is the main problem I am having

 

=======

qry_v2_tbl

=======

works fine
uses tbl as source and not qry

.

@manny213 

I don't normally download files from external sites such as OneDrive but I made an exception in your case. You couldn't upload your file because it was HUGE...approx 43MB because one of the tables contained over 1.1 million records - mostly duplicates. I've removed all the duplicates and only 67 records were left! After compacting, it reduced to about 500kB - approx 100 times smaller.

 

Looks very much like you are used to working in Excel and haven't grasped the basic concepts of Access

You are trying to do some complex subquery work but have ignored proper database design

 

1, Neither table has a primary key field. I've added an autonumber ID field to each table as a PK field

2. You are duplicating data unnecessarily: Store & QuoteDate

3. I've added a table tbl_Store with 2 fields StoreID (autonumber OK) & Store (text) then replaced Store with StoreID in the other 2 tables.

4. The Row_Number field in tbl_PriceChanges is superfluous as its the same as the PriceChangeID PK field

You only have 1 entry for each date in tbl_PriceChanges which means that table isn't needed.

5. I've added the PriceChange field to tblData and populated it.

 

So you now only need two tables tblStore & tbl_Data.

I've created a relationship between them & added referential integrity

 

The old tables can now be deleted as can your 5 queries & my update query. All items ready for deletion are prefixed with a #.

 

Next I've created a much simpler query qryStoreData based on the 2 remaining tables.

 

SELECT tbl_Store.Store, tbl_Data.quote_date, tbl_Data.store_price, tbl_Data.Price_Change
FROM tbl_Store INNER JOIN tbl_Data ON tbl_Store.StoreID = tbl_Data.StoreID;

 

 

Finally based on that I've created qryPriceChangeStDev 

 

SELECT qryStoreData.Store, StDev(qryStoreData.Price_Change) AS StDev
FROM qryStoreData
GROUP BY qryStoreData.Store;

 

This has one record with the StDev for price changes for the only store in your data.

Is that what you want? See attached screenshot (Capture.PNG)

 

If not, please use qryStoreData as a starting point to get the end result you want

 

Hope that helps you move forward. Suggest you study a book on the basics of database design

 

 

 

 

Thanks for the reply

The database I sent is a small subset of the full database. The repeating values are there by design. There are other fields in the table that uniquely identify each record. The values I care about for the purpose of this query are going to be repeating. That is why I have a DISTINCT keyword in my base query for QRY_LOG_PRICE_CHANGES.

I intentionally did not want a table added. The tables add to the size of the DB so I have decided to rely on queries to provide data for other queries. Not sure if this is in line with proper DB practices but that is what I did. I am not opposed to them if they are truly needed.

The STDEV calculation is a rolling calculation. For example, on Nov 3 2021 go back 10 days and use those 10 days to calculate the STDEV (Oct 25 to Nov 3). On Nov 2 2021 go back 10 days and use those 10 days to calculate the STDEV (Oct 24 to Nov 2) etc.

I have the calculation working as I have envisioned it but the problem I am having is that it will not accept QRY_LOG_PRICE_CHANGES as a base. It will only work if TBL_LOG_PRICE_CHANGES is used instead. This is my problem that I am trying to resolve. Do you know why that is the case?

@manny213

The repeating values may be there by design but its a big mistake.
Sorry if it appears rude but, as stated, the design is very badly flawed in several ways. No primary key fields. No indexes. Duplicated data. If you want those types of data table, use Excel NOT Access.

Adding tables can reduce database size where they prevent the need for repeated data. Using the ID value in each record takes up far less space & makes it less likely that there will be data entry errors. To remind you , the changes I made meant the database size was reduced from 43MB to 500kB approx.


You can easily modify the StDev query I provided to filter it for selected date ranges.
For example:
SELECT qryStoreData.Store, StDev(qryStoreData.Price_Change) AS StDev
FROM qryStoreData
WHERE (((qryStoreData.quote_date) Between #3/9/2020# And #3/19/2020#))
GROUP BY qryStoreData.Store;

 

or using parameters:
SELECT qryStoreData.Store, StDev(qryStoreData.Price_Change) AS StDev
FROM qryStoreData
WHERE (((qryStoreData.quote_date) Between [Enter Start Date] And [Enter End Date]))
GROUP BY qryStoreData.Store;


Having spent well over an hour going through this and making it workable, I'm really not willing to spend any more time analysing the original database.

 

You need to change the table structure - the sooner the better. It will take a little time to do so but will save you a huge amount of time in the long run. I assure you it will be worthwhile.

 

Good luck with your project

 

is anyone able to help me with this?