473,396 Members | 2,013 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,396 software developers and data experts.

Inserting data giving error message

Hello All,

I'm really new to this, so sorry ahead of time. Trying to get data to be posted into a table along with other information that's already being put into there.

I'm using access 2003.

After hitting to post I get the error message : Run-time error '3346'


Here is the code:
Expand|Select|Wrap|Line Numbers
  1.     If Me.redeem > 0 Then
  2.         DoCmd.RunSQL "INSERT INTO closingsales ( redeem ) " & _
  3.             "SELECT #" & startdate & "# AS Expr1, " & _
  4.             Me.redeem & " AS Expr5"
  5.     End If
  6.  
I have added the column for redeem into closingsales already and checked other queries to try and find out if there's something I'm missing.
Sep 18 '08 #1
4 1727
Stewart Ross
2,545 Expert Mod 2GB
Hi. Can't say I know anything about that error message, but one obvious problem is that you have a select statement which is selecting two items, and you are using that for an insert which lists only one item (redeem). Two into one won't go.

The insert will create new rows for any data added; is it the case that you want to update existing rows instead? It is not clear from what you have posted, but if you really want to update the value you will need an update query (not an insert).

-Stewart
Sep 18 '08 #2
Hi. Can't say I know anything about that error message, but one obvious problem is that you have a select statement which is selecting two items, and you are using that for an insert which lists only one item (redeem). Two into one won't go.

The insert will create new rows for any data added; is it the case that you want to update existing rows instead? It is not clear from what you have posted, but if you really want to update the value you will need an update query (not an insert).

-Stewart
There are 3 things already being posted to the table. I am trying to get this posted along with them as well. I have tried to add redeem into the code already being used, but that did not work.

This is the code that is being used already:

Expand|Select|Wrap|Line Numbers
  1. 'DoCmd.OpenQuery "CRS Append Closingsales", acViewNormal, acEdit
  2.     DoCmd.RunSQL "INSERT INTO closingsales ([Date], Cash, iou, change) " & _
  3.         "SELECT DISTINCTROW #" & startdate & "# AS Expr1, " & _
  4.         "[forms]![depositform]![closecash] AS Expr2, [forms]![depositform]![closeiou] " & _
  5.         "AS Expr3, [forms]![depositform]![rollchange] AS Expr4 WITH OWNERACCESS OPTION"
  6.     If Me.IOUCheck > 0 Then
  7.         DoCmd.RunSQL "INSERT INTO deposits ( [date], id, Amount ) " & _
  8.             "SELECT #" & startdate & "# AS Expr1, 99 AS Expr2, " & _
  9.             Me.IOUCheck & " AS Expr3"
  10.  
Sorry for not being as clear as I should be, I'm still trying to figure all this out. Thank you for the help!

I'm not sure if that helps any on what it is I'm trying to get done.
Sep 18 '08 #3
Stewart Ross
2,545 Expert Mod 2GB
Hi. You cannot include the form control references within your SQL string - these will not be recognised as valid field names by the Access database engine. It is possible to include their values, which should work. If the control contains a string value you need to ensure that the value is preceded and followed by a single quote, as shown below (for the first of the form control references only - you will need to adjust the others yourself if they too are strings, or remove them from the first field if the closecash value is just a number).

Expand|Select|Wrap|Line Numbers
  1. "SELECT DISTINCT #" & startdate & "# AS Expr1, '" & _
  2.         [forms]![depositform]![closecash] & "' AS Expr2, " & [forms]![depositform]![closeiou] & _
  3.         " AS Expr3, " & [forms]![depositform]![rollchange] & " AS Expr4 WITH OWNERACCESS OPTION"
I do not know why you are using the OpenQuery method as well as RunSQL; I am sure there will be a valid reason for it.

I have substituted the more general SELECT DISTINCT in place of the Access-specifc SELECT DISTINCTROW syntax in your select clause. I'm not sure why you need the WITH OWNERACCESS part - it should work perfectly well without it unless you have some form of access restriction to work round or something.

-Stewart

ps there is no mention of field 'redeem' in the code you posted. There is only a field called 'Date' - not a good choice of name, although allowable as a field name. It can cause considerable confusion with the built-in function to obtain today's date - the Date function.
Sep 18 '08 #4
Hi. You cannot include the form control references within your SQL string - these will not be recognised as valid field names by the Access database engine. It is possible to include their values, which should work. If the control contains a string value you need to ensure that the value is preceded and followed by a single quote, as shown below (for the first of the form control references only - you will need to adjust the others yourself if they too are strings, or remove them from the first field if the closecash value is just a number).

Expand|Select|Wrap|Line Numbers
  1. "SELECT DISTINCT #" & startdate & "# AS Expr1, '" & _
  2.         [forms]![depositform]![closecash] & "' AS Expr2, " & [forms]![depositform]![closeiou] & _
  3.         " AS Expr3, " & [forms]![depositform]![rollchange] & " AS Expr4 WITH OWNERACCESS OPTION"
I do not know why you are using the OpenQuery method as well as RunSQL; I am sure there will be a valid reason for it.

I have substituted the more general SELECT DISTINCT in place of the Access-specifc SELECT DISTINCTROW syntax in your select clause. I'm not sure why you need the WITH OWNERACCESS part - it should work perfectly well without it unless you have some form of access restriction to work round or something.

-Stewart

ps there is no mention of field 'redeem' in the code you posted. There is only a field called 'Date' - not a good choice of name, although allowable as a field name. It can cause considerable confusion with the built-in function to obtain today's date - the Date function.
Hi, thank you again for the help. I was unaware of the different types of code in there. The person that wrote this is long gone from here and this is my first attempt at any of this. So thanks for being patient.
Sep 18 '08 #5

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

Similar topics

2
by: Josh Strickland | last post by:
I am attempting to create an Access database which uses forms to enter data. The issue I am having is returning the query results from the Stored Procedure back in to the Access Form. ...
5
by: hfk0 | last post by:
Hi, I'm new to ASP.net, SQL Server and visual studio.net, and I'm having problem inserting and storing data from a web form to a SQL database. I created a simple ASP.NET web form, a simple SQL...
2
by: pramod | last post by:
Hi I am facing the problem while inserting the spanish characters in the DB2 UDB v8.2 database. We are pulling the data from SQL server through informatica and then pushing the same in the DB2...
0
by: pd123 | last post by:
I'm new to C# and .net and I'm trying to create a form that will register users in a sql server database. I have the following code but when I run the code I get an error " The name 'Peter' is...
1
by: gouse | last post by:
Hello Friends, In a Table I am inserting more than 50,000 Records one by one. It was taking a lot of time . Is it There any good approach/solution for inserting records more than 50,000 one by one...
10
by: Rahul Babbar | last post by:
Hi, I am getting the following error, while executing the simple insert script on a few tables. INSERT INTO <table_name>(<col1>) VALUES (1); DB2 SQL error: SQLCODE: -440, SQLSTATE: 42884,...
6
by: Bunty | last post by:
I want to insert values in the database.If i insert values one by one then it works till 4 or 5 fields then after it gives error.In my database there are more than 20 field.Pls help me.
2
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography...
1
by: nmsreddi | last post by:
HI Friends i am using sqlserver2005 . I have column in my table with xml DataType .and while i am inserting data into it ,if '&' is there in data it is giving xml parser error as "XML...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
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 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.