473,387 Members | 1,423 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,387 software developers and data experts.

Error 3061, Too few parameters Expected 1

106 100+
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 the Autonumber field.
Reg is a required field.

Your help is appreciated.

Expand|Select|Wrap|Line Numbers
  1. DIM NewACCVehicleID As Long
  2. DIM strVehicleInsert As String
  3.  
  4. NewACCVehicleID = DMax("ACCVehicleID", "ACC_Vehicle") + 1
  5. strVehicleInsert = "INSERT INTO [ACC_Vehicle] ( ACCVehicleID, Reg, Make, Model ) " & _
  6. "SELECT " & NewACCVehicleID & " As NewID, Reg, VehicleMake, VehicleModel " & _
  7. "FROM [tbl_Accident] WHERE AccidentID = " & Me.AccidentId & ";"
  8. DBEngine(0)(0).Execute strVehicleInsert, dbFailOnError
  9.  
Jul 30 '10 #1

✓ answered by patjones

This happens with aggregate functions (DLookup, DMax, etc.) when the function can't find anything. If you set var = DLookup(...) and DLookup doesn't return anything, then var is set to null.

So somehow your DLookup call is not returning anything. It is always good procedure to put a DLookup call inside Nz() to account for the possibility of getting no results and avoiding a null value.

Naturally, you might also want to determine why your DLookup is not returning a result in the first place.

Pat

3 1797
patjones
931 Expert 512MB
One issue I see here is that you are trying to manually assign the ID. If this is an autonumber column, Access will automatically assign the ID according to what the next number in the existing sequence is. Thus, you should only need to include your other columns in the INSERT.

You can get a feel for this concept by opening the table in datasheet view and entering a record by hand. Access will fill in the autonumber ID column for you.

I might add however, that if your ID column weren't an autonumber, using DMax to obtain the highest existing ID and incrementing it by 1 to get the next ID is a great way to manually assign ID's.

Pat
Jul 30 '10 #2
tasawer
106 100+
HI,

Thanks for your reply.

I have used Reg as the new id and now it works succefully (Code Below).
Service field determines if the vehicle is in repair or not. I have set this field to true.

If the vehicle is in repair (Service=true) I wish to disable a command button.
This code gives me "invalid use of Null".
however, if all details are entered manually into the ACC_Vehicle table, then this code does not give an error)
Expand|Select|Wrap|Line Numbers
  1. DIM inService As Boolean
  2. inService = DLookup("Service", "ACC_Vehicle", "ACCVehicleID=" & Me.ACCVehicleID)
  3. Me.cmdRepairInvoice.Enabled = Not inService
  4.  
SQL to insert New data (all fields are inserted as expected)
Expand|Select|Wrap|Line Numbers
  1. strVehicleInsert = "INSERT INTO [ACC_Vehicle] ( Reg, Make, Model, Service, VehicleOwnerID ) " & _
  2. "SELECT '" & Me.RegNo & "' As NewID, VehicleMake, VehicleModel, -1, '" & txtContactID & "' " & _
  3. "FROM [tbl_Accident] WHERE AccidentID = " & Me.AccidentId & ";"
  4. DBEngine(0)(0).Execute strVehicleInsert, dbFailOnError
Jul 30 '10 #3
patjones
931 Expert 512MB
This happens with aggregate functions (DLookup, DMax, etc.) when the function can't find anything. If you set var = DLookup(...) and DLookup doesn't return anything, then var is set to null.

So somehow your DLookup call is not returning anything. It is always good procedure to put a DLookup call inside Nz() to account for the possibility of getting no results and avoiding a null value.

Naturally, you might also want to determine why your DLookup is not returning a result in the first place.

Pat
Jul 30 '10 #4

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

Similar topics

1
by: Cathy | last post by:
I get this error "Too few parameters. Expected 1" when trying to run the following code. Can someone please help me. Thanks in advance Dim db As DAO.Database ' Current database Dim...
0
by: Miranda Evans | last post by:
I noticed several postings about issues related to "run-time error 3061", and I observed that the solutions to these issues appear to involve correcting something within the SQL code. I'm...
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,...
2
by: fanfromfla | last post by:
I am using a database that has worked for many years for a holiday project for needy families. My organization recently upgraded its server and changed everyone to Windows XP. I just mention that...
1
by: bonnie.tangyn | last post by:
Hello all I get Too few parameters expected 2 error and "The MS Jet Database engine cannot find the input table or query "myTempTablename". Make sure it exists and that its name is spelled...
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
8
Cintury
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....
9
by: bullfrog83 | last post by:
I'm getting "Error 3061: To few parameters. Expected 2." in the CurrentDb.Execute lines in the following code: 'variables previously defined 'rstCust previously defined 'rstStdCourses...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.