Error while running insert query

novice

Registered User.
Local time
Today, 12:56
Joined
Jun 3, 2009
Messages
32
Hi,

While I'm trying to run "insert into" query when "save" button is pressed, i'm getting the following error:
"No value given for one or more required parameters."

Below is the query:

stSql = "INSERT INTO [CUSTOMER] (CustID, Weight, AGE) VALUES (txtCustId, txtWeight, comboAge)"
rs.Open stSql, con

"txtCustID", "txtWeight", "comboAge" are the textboxes and combobox present in the form.

I have tried giving txtCustId.value in query, but still i'm getting the same error.
Can any one let me know on how to resolve this. Thanks.
 
What are the data types of the 3 fields?
 
Following are the datatypes for the fields present in table
CustID = Number
Weight = Number
AGE = Number
 
I wonder if it isn't the SQL String but this code

rs.Open stSql, con

giving you the problem.

use

CurrentDb.Execute stSQL, dbFailOnError

instead.
 
Try this:


stSql = "INSERT INTO [CUSTOMER] (CustID, Weight, AGE) VALUES (" & Me.txtCustId & ", " & Me.txtWeight & ", " & Me.comboAge & ")"
 
Hi,

In some cases, Weight and age are optional fields. When i execute the query with null values i'm getting "Syntax error in INSERT INTO statement". How can i resolve this with the query?.
 
Try

Nz(Me.txtWeight, 0)

which should insert a zero. If you don't want anything to be inserted, we'll need to go a different direction.
 
Hi,

I'm in a case where i dont want anything to be inserted for age field. How can i go about with this?.
 
Try this; I have to run over to our airport office, so can't test:

Nz(Me.txtWeight, "Null")
 
Thanks for your quick reply. But i have already tried with that but i'm getting error message. BTW, now i'm using SELECT query to lookup the entry in which weight can be NULL. (I think this wont effect much).
 
Are you familiar with recordsets? When I have a situation where values might be null, I generally open a recordset on the table and use AddNew to add the record instead of SQL.
 

Users who are viewing this thread

Back
Top Bottom