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 would be greatly appreciated. -
Sub CalcLoop()
-
-
Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
Set db = CurrentDb
-
Set rs = db.OpenRecordset("qry_FleetRS", dbOpenDynaset)
-
-
rs.MoveFirst
-
-
Do While Not rs.EOF
-
-
rs.MoveNext
-
Loop
-
-
Call FleetCalc
-
-
rs.Close
-
-
Set rs = Nothing
-
Set db = Nothing
-
-
End Sub
-
-
8 4480
It sounds like there might be an error in the SQL of qry_FleetRS. Does the query run without problems if you open it manually?
Hi,
Yes it does. The underlying query is selecting all fields from a table where one field is equal to a field on an open form.
Thanks
Viv
Here is the query in SQL -
SELECT tbl_NCBCalcs.QuoteID, tbl_NCBCalcs.REGISTRATIONNO, tbl_NCBCalcs.NCBE1, tbl_NCBCalcs.NCBE2, tbl_NCBCalcs.NCBE3, tbl_NCBCalcs.NCBE4, tbl_NCBCalcs.NCBE5, tbl_NCBCalcs.StartingNCB, tbl_NCBCalcs.POIS1, tbl_NCBCalcs.POIE1, tbl_NCBCalcs.IAF1F, tbl_NCBCalcs.POIS2, tbl_NCBCalcs.POIE2, tbl_NCBCalcs.IAF2F, tbl_NCBCalcs.POIS3, tbl_NCBCalcs.POIE3, tbl_NCBCalcs.IAF3F, tbl_NCBCalcs.POIS4, tbl_NCBCalcs.POIE4, tbl_NCBCalcs.IAF4F, tbl_NCBCalcs.POIS5, tbl_NCBCalcs.POIE5, tbl_NCBCalcs.IAF5F, tbl_NCBCalcs.StartPOI1, tbl_NCBCalcs.StartPOI2, tbl_NCBCalcs.StartPOI3, tbl_NCBCalcs.StartPOI4, tbl_NCBCalcs.StartPOI5, tbl_NCBCalcs.PercentageE1, tbl_NCBCalcs.PercentageE2, tbl_NCBCalcs.PercentageE3, tbl_NCBCalcs.PercentageE4, tbl_NCBCalcs.PercentageE5, tbl_NCBCalcs.StartPOIDate, tbl_NCBCalcs.StartPOI6, tbl_NCBCalcs.NCBID
-
FROM tbl_NCBCalcs
-
WHERE (((tbl_NCBCalcs.QuoteID)=[Forms]![frm_Fleet]![QuoteID]));
-
I don't often use form references in query, so I am a bit rusty in that regard.
What happens if you try: - Sub CalcLoop()
-
-
Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
dim lngQuoteID as long
-
lngQuoteID=Forms!frm_Fleet!QuoteID
-
Set db = CurrentDb
-
Dim strSQL as string
-
strSQL="SELECT tbl_NCBCalcs.QuoteID, tbl_NCBCalcs.REGISTRATIONNO, tbl_NCBCalcs.NCBE1, tbl_NCBCalcs.NCBE2, tbl_NCBCalcs.NCBE3, tbl_NCBCalcs.NCBE4, tbl_NCBCalcs.NCBE5, tbl_NCBCalcs.StartingNCB, tbl_NCBCalcs.POIS1, tbl_NCBCalcs.POIE1, tbl_NCBCalcs.IAF1F, tbl_NCBCalcs.POIS2, tbl_NCBCalcs.POIE2, tbl_NCBCalcs.IAF2F, tbl_NCBCalcs.POIS3, tbl_NCBCalcs.POIE3, tbl_NCBCalcs.IAF3F, tbl_NCBCalcs.POIS4, tbl_NCBCalcs.POIE4, tbl_NCBCalcs.IAF4F, tbl_NCBCalcs.POIS5, tbl_NCBCalcs.POIE5, tbl_NCBCalcs.IAF5F, tbl_NCBCalcs.StartPOI1, tbl_NCBCalcs.StartPOI2, tbl_NCBCalcs.StartPOI3, tbl_NCBCalcs.StartPOI4, tbl_NCBCalcs.StartPOI5, tbl_NCBCalcs.PercentageE1, tbl_NCBCalcs.PercentageE2, tbl_NCBCalcs.PercentageE3, tbl_NCBCalcs.PercentageE4, tbl_NCBCalcs.PercentageE5, tbl_NCBCalcs.StartPOIDate, tbl_NCBCalcs.StartPOI6, tbl_NCBCalcs.NCBID " & _
-
" FROM tbl_NCBCalcs " & _
-
" WHERE (((tbl_NCBCalcs.QuoteID)=" & lngQuoteID & "));
-
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
-
-
rs.MoveFirst
-
-
Do While Not rs.EOF
-
-
rs.MoveNext
-
Loop
-
-
Call FleetCalc
-
-
rs.Close
-
-
Set rs = Nothing
-
Set db = Nothing
-
-
End Sub
Hi
That works, insofar as it no longer gives me the parameter error, however it is not looping through and updating all records. It only updates the first record and then stops.
Any suggestions?
You have a loop which is not doing anything at all at present - Do While Not rs.EOF
-
rs.MoveNext
-
Loop
-
This just loops to the end of file. You have not posted the Update part of your code / SQL; I presume that it's done by the Call Fleetcalc line (line 21 in your original post).
Shouldn't that call be within the loop? I cannot be sure about this, as if you have reached the end of file any call afterwards is surely invalid, but as you have not posted the relevant section it's hard to know for sure.
-Stewart
Thanks Stewart,
I just cannot seem to get it to move to the next record and perform the updates.
I have a query set up which retrieves the same records as the SQlStr in my code, and this query is returning the correct number of records.
I have not posted the code for Sub FleetCalc, as this in turn runs a number of update queries and calls other procedures dependant on which conditions are true for a particular record.
I have amended my code (below), which is updating perfectly on the first record in the recordset. Any further suggestions would be welcomed. I am no expert, so any assistance is greatly appreciated. -
Sub CalcLoop()
-
-
Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
Dim lngQuoteID As Integer
-
-
lngQuoteID = Me!QuoteID
-
'QuoteID = Me.QuoteID
-
-
Set db = CurrentDb
-
-
Dim strSQL As String
-
-
strSQL = "SELECT tbl_NCBCalcs.QuoteID, tbl_NCBCalcs.REGISTRATIONNO, tbl_NCBCalcs.NCBE1, tbl_NCBCalcs.NCBE2, tbl_NCBCalcs.NCBE3, tbl_NCBCalcs.NCBE4, tbl_NCBCalcs.NCBE5, tbl_NCBCalcs.StartingNCB, tbl_NCBCalcs.POIS1, tbl_NCBCalcs.POIE1, tbl_NCBCalcs.IAF1F, tbl_NCBCalcs.POIS2, tbl_NCBCalcs.POIE2, tbl_NCBCalcs.IAF2F, tbl_NCBCalcs.POIS3, tbl_NCBCalcs.POIE3, tbl_NCBCalcs.IAF3F, tbl_NCBCalcs.POIS4, tbl_NCBCalcs.POIE4, tbl_NCBCalcs.IAF4F, tbl_NCBCalcs.POIS5, tbl_NCBCalcs.POIE5, tbl_NCBCalcs.IAF5F, tbl_NCBCalcs.StartPOI1, tbl_NCBCalcs.StartPOI2, tbl_NCBCalcs.StartPOI3, tbl_NCBCalcs.StartPOI4, tbl_NCBCalcs.StartPOI5, tbl_NCBCalcs.PercentageE1, tbl_NCBCalcs.PercentageE2, tbl_NCBCalcs.PercentageE3, tbl_NCBCalcs.PercentageE4, tbl_NCBCalcs.PercentageE5, tbl_NCBCalcs.StartPOIDate, tbl_NCBCalcs.StartPOI6, tbl_NCBCalcs.NCBID " & _
-
" FROM tbl_NCBCalcs " & _
-
" WHERE (((tbl_NCBCalcs.QuoteID)=" & lngQuoteID & "));"
-
-
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
-
-
rs.MoveFirst
-
-
Do Until rs.EOF
-
-
Call FleetCalc 'Calls multiple procedures and queries to update almost every field in the recordset, dependant on a range of conditions.
-
-
rs.MoveNext
-
-
Loop
-
-
rs.Close
-
-
Set rs = Nothing
-
Set db = Nothing
-
-
End Sub
-
Thanks Stewart and TheSmileyCoder.
Without your assistance I would not have made it this far.
I have managed to resolve the last problem. It appears that I was dealing with a .EOF issue. I still have one more error to fix, and once complete I will post the final working code.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: kbrad |
last post by:
I am using the following code in asp to select some data from an access db.
recSel is defined and set further up my webpage, as is rsUpdate User.
I cannot work out how to get past this error...
|
by: Dee |
last post by:
Running an AfterUpdate event procedure, I get the following error:
"Too few parameters. Expected 1."
My code is as follows:
Private Sub DealerID_AfterUpdate()
Dim db As DAO.Database
|
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". ...
|
by: javediq143 |
last post by:
Hi all,
I got one more prob in another ASP page linked to the earlier one. I've created an Access DB and created a query using Access Query wizard. The query is running fine in Access and it is...
|
by: Nano |
last post by:
I have created ASP file from MS Access. It has the following Code. But
it gives an error at:
rs.Open sql, conn, 3, 3
The Error is:
Error Type:
Microsoft OLE DB Provider for ODBC Drivers...
| |
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
|
by: Cintury |
last post by:
The problem is I have a function that I've created and stored in a module. I call it as an expression (e.g. total: Function(parameter)). I'm receiving the error 3061: too few parameters, expected 1....
|
by: hannoudw |
last post by:
I tried to figure out what i did wrong, and i couldn't find the mistake could any one help me ??
i'm getting this message :Error 3061, Too few parameters Expected 1.
achat_num and fact_num are both...
|
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 =...
|
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"...
|
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...
| |
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...
|
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: 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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
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...
| |