473,394 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Error 3061 Too few parameters Expected 1

Seth Schrock
2,965 Expert 2GB
This one really has me puzzled. Normally I know how to deal with this type of error, but this time it is defying all my troubleshooting knowledge.

I have a query def (qryCustomerCreditScore). In my VBA code, I'm opening a recordset based on this query that sums some of the fields, counts another one, and then performs a custom function based on the last one. It is when I open this recordset that I get the Too few parameters error. So, as I normally do, I set a breakpoint and then used the immediate window to pull my SQL string from the VBA, copied and pasted it into a query def and then ran it. No error was returned. However, no records were returned. So I decided to run qryCustomerCreditScore(I'm still in Break mode) and it didn't return any records either. I then stopped my code and re-ran qryCustomerCreditScoreand it now returns records. So I run my query def based on my VBA SQL string and it works fine. I try to run it again through the code and it errors out again. While still in break mode I run qryCustomerCreditScoreand no records are returned.

I have never seen this or read about it online. Normally I would say that I got a field name typed incorrectly, but that doesn't seem to be the case this time since it all works fine when not being ran through code. I don't know if this matters, but my tables are stored on SQL Server connected through ODBC drivers (DSN-less connection).

Here is the code for qryCustomerCreditScore:
Expand|Select|Wrap|Line Numbers
  1. SELECT CustID_pk
  2. , QuoteID_fk
  3. , GetIndividualCS([CustID_pk]) AS CreditScore
  4. , CustFN
  5. , CustLN
  6. , Income
  7. , CollNum
  8. , CollAmt
  9. , ITIN
  10. FROM tblCustomers
  11. WHERE QuoteID_fk=[Forms]![frmConsumerMortgageCalculator]![QuoteID]
  12.  
Here is the VBA code up to the line that errors out (line 18):
Expand|Select|Wrap|Line Numbers
  1. Private Sub SetValues()
  2. On Error GoTo Error_Handler
  3.  
  4. Dim db As DAO.Database
  5. Dim strQuote As String
  6. Dim rstQuote As DAO.Recordset
  7. Dim strCust As String
  8. Dim rstCust As DAO.Recordset
  9.  
  10.  
  11. Set db = CurrentDb
  12. strQuote = "SELECT * FROM tblQuotes WHERE QuoteID = " & lngQuoteID
  13. Set rstQuote = db.OpenRecordset(strQuote, dbOpenDynaset, dbSeeChanges)
  14.  
  15. strCust = "SELECT QuoteID_fk, Sum(Income) AS LnIncome, Sum(CollNum) AS LnCollNum, " & _
  16.           "Sum(CollAmt) AS LnCollAmt, Count(ITIN) AS IsITIN, GetLoanCS([QuoteID_fk]) AS CreditScore " & _
  17.           "FROM qryCustomerCreditScore GROUP BY QuoteID_fk"
  18. Set rstCust = db.OpenRecordset(strCust, dbOpenDynaset, dbSeeChanges)
The strCust string concatenates out to
Expand|Select|Wrap|Line Numbers
  1. SELECT QuoteID_fk
  2. , Sum(Income) AS LnIncome
  3. , Sum(CollNum) AS LnCollNum
  4. , Sum(CollAmt) AS LnCollAmt
  5. , Count(ITIN) AS IsITIN
  6. , GetLoanCS([QuoteID_fk]) AS CreditScore 
  7. FROM qryCustomerCreditScore 
  8. GROUP BY QuoteID_fk
  9.  
I can't think of any other details that would be necessary, but like I said, I don't know what to look at right now. If I have missed something, just ask and I will provide it.
Jul 14 '14 #1

✓ answered by twinnyfo

AND!!! I just realized that you were using the "Forms!" reference as a parameter in your query. When you use queries in such a manner (I've run across this a few times), you can't query that query in another query (if you at all followed this). You would have to find another way to limit the values.

7 1708
twinnyfo
3,653 Expert Mod 2GB
Seth,

Check line 3 of your first block of code and line 16 of your second block.

Block 1, Line 3 says:

Expand|Select|Wrap|Line Numbers
  1. GetIndividualCS([CustID_pk]) AS CreditScore
Block 2, Line 16 says:

Expand|Select|Wrap|Line Numbers
  1. GetLoanCS([QuoteID_fk]) AS CreditScore
Since the only query referenced is qryCustomerCreditScore, you may be confusing your SQL string.

Also, if this does not resolve it, have you considered calculating out the Credit Score after the record(s) is returned? Not sure if that would make a difference....

Cheers!
Jul 14 '14 #2
twinnyfo
3,653 Expert Mod 2GB
AND!!! I just realized that you were using the "Forms!" reference as a parameter in your query. When you use queries in such a manner (I've run across this a few times), you can't query that query in another query (if you at all followed this). You would have to find another way to limit the values.
Jul 14 '14 #3
Seth Schrock
2,965 Expert 2GB
I changed the alias in qryCustomerCreditScore to be IndCreditScore so that field is now
Expand|Select|Wrap|Line Numbers
  1. GetIndividualCS([CustID_pk]) AS IndCreditScore
I still get the error.

For which one are you suggesting that I calculate the credit score after the record is returned? For the GetIndividualCS function, it is taking up to three different credit scores from a related table and using special code to choose one of them for a specific person. GetLoanCS then takes the credit scores selected for each person and makes a selection from one of them.

I do have to have the query def because I use it in other situations as well, but I could try to combine my two queries into one for my VBA code. I'll let you know how this works.
Jul 14 '14 #4
Seth Schrock
2,965 Expert 2GB
I don't know for sure, but I would be surprised if I hadn't queried another query that used the Forms! reference. I'll give it a shot though. Maybe my idea to combine the two queries would fix it.
Jul 14 '14 #5
twinnyfo
3,653 Expert Mod 2GB
A couple ways to use Form values without the Forms! reference is to use either global variables (which still requires you to create a tiny funciton that returns the value of the variable) or TempVars, which acts like a global variable, but can be used as is.... I am still not comfortable using Temp Vars, although I have found that it does work.

I think either one would work in these situations.

Hope this hepps!
Jul 14 '14 #6
Seth Schrock
2,965 Expert 2GB
Well, I got it to work. First I combined it and left the Forms! reference in it and it still errored out. Then I ended up using a variable to pass the value I needed to the query so that my query was using the actual number instead of a reference and it worked.

I am curious as to why it doesn't work to use VBA to query a query def that has a Forms! reference in it or create a SQL string in VBA that has the Forms! reference. It seems strange.

Anyway, thanks twinnyfo for leading me in the right direction. I don't think that I would have considered that.
Jul 14 '14 #7
twinnyfo
3,653 Expert Mod 2GB
Seth,

Without my own pounding my head against a brick wall with the same error in the same situation, I would never have known. I forget where I found this soultion, but no one was able to provide a "why". Maybe the reference is just too far removed from itself--I don't have a clue.

But, I am glad we gould get you to a solution!
Jul 14 '14 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Steve Richfield | last post by:
There have been LOTS of postings about error 3061, but mine seems to be an even simpler case than the others. I have a simple **FUNCTIONING** query called qryEdits. Copying the SQL from the query,...
4
by: Richard Hollenbeck | last post by:
I thought I was very specific in this SQL request. There is a form open with a selected record (and a corresponding "lngRecipeID" on that form. The table also has a field called "lngRecipeID". ...
1
by: Richard Hollenbeck | last post by:
I wonder what I'm missing? I really feel like a retard because I've been screwing with some code for a very long time. I just must be missing something very simple. In the following example,...
3
by: phill86 | last post by:
Hi, I am trying to run the following query in a recordset and i get the following error message Runtime error 3061 - Too few parameters. Expected 1 i am using the following code
3
by: tasawer | last post by:
Hi, I need to add a new record to table "ACC_Vehicle", with three pieces of information. When I activate the code, I get the error "Error 3061, Too few parameters Expected 1" ACCVehicleID is...
6
by: dowlingm815 | last post by:
I am receiving error code too few parameters. Expected 1. I can't seem to find the issue. The error code occurs when on this line of code: Set rstTemp =...
4
by: shalskedar | last post by:
In my DB(Ms Access 2003)I want to delete a record from 1 table which is linked to another table. For ex- There are 2 tables "MasterType" which is the Master table & another table as "Sash DO"...
7
by: bunchaCoconuts | last post by:
I'm trying to figure out why I'm getting this error. I'm relatively inexperienced. The nature of the following code is that a slightly different query is run whether or not the "ImportantDatesOnly"...
8
by: Viv Jones | last post by:
Hi I am trying to update a recordset, however, I cannot get the code to run as i get Runtime Error: 3061. Too Few Parameters. Expected 1. Line 6 is highlighted when you debug. Any assistance...
2
by: baruc308 | last post by:
I cant run this. please help! the error is run-time error 3061 too few parameters expected 1 in this line --------->> Set rs = db.OpenRecordset <---- below Public Function...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.