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. -
DIM NewACCVehicleID As Long
-
DIM strVehicleInsert As String
-
-
NewACCVehicleID = DMax("ACCVehicleID", "ACC_Vehicle") + 1
-
strVehicleInsert = "INSERT INTO [ACC_Vehicle] ( ACCVehicleID, Reg, Make, Model ) " & _
-
"SELECT " & NewACCVehicleID & " As NewID, Reg, VehicleMake, VehicleModel " & _
-
"FROM [tbl_Accident] WHERE AccidentID = " & Me.AccidentId & ";"
-
DBEngine(0)(0).Execute strVehicleInsert, dbFailOnError
-
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
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
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) -
DIM inService As Boolean
-
inService = DLookup("Service", "ACC_Vehicle", "ACCVehicleID=" & Me.ACCVehicleID)
-
Me.cmdRepairInvoice.Enabled = Not inService
-
SQL to insert New data (all fields are inserted as expected) -
strVehicleInsert = "INSERT INTO [ACC_Vehicle] ( Reg, Make, Model, Service, VehicleOwnerID ) " & _
-
"SELECT '" & Me.RegNo & "' As NewID, VehicleMake, VehicleModel, -1, '" & txtContactID & "' " & _
-
"FROM [tbl_Accident] WHERE AccidentID = " & Me.AccidentId & ";"
-
DBEngine(0)(0).Execute strVehicleInsert, dbFailOnError
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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,...
|
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...
|
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...
|
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: 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,...
|
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: 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...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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: 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,...
|
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...
| | |