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

Error Message: Number of query values and destination fields are not the same.

153 100+
I'm getting this error message: Number of query values and destination fields are not the same.

This is the code:

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO tblDateDifference (  DateDifference )
  2. SELECT tblContracts.EndDate As EndDate, 
  3. IIf([Date()] > EndDate, DaysToCompletion(EndDate), DaysCompleted(EndDate)) AS DateDifference,
  4. FROM tblContracts;
Can someone please tell me why I'm getting this error message? PLEASE?!?! lol
Dec 7 '06 #1
9 3341
MSeda
159 Expert 100+
Delete tblContracts.EndDate As EndDate, from the select statement. You only want the value returned from the iif statement to be inserted, correct.
Dec 7 '06 #2
Kosmos
153 100+
No the select statement is necessary...then the IIf statements put the selected date into a module based on their values.
Dec 7 '06 #3
MSeda
159 Expert 100+
You only have one destination field listed, DateDifference, in the INSERT INTO statement. Anything listed in the SELECT statement SQL will try to insert into the feilds designated in the INSERT INTO clause. In your SELECT statement you have two values DateEnd and DateDifference, hence the error message. You will either have to add DateEnd into your list of destination fields or drop it from the SELECT statement.
If you are trying to insert datedifference only for certain enddates you need to incorporate enddate into a WHERE clause
Dec 7 '06 #4
Kosmos
153 100+
DateDifference is what it's being assigned to I thought? I thought I was saying Insert into blah blah
Select blah blah as EndDate (I thought this was assigning it with a temporary name) then saying iif(so and so....blah blah come up with value) then assign the object I'm inserting into AS DateDifference

Is this incorrect?

Well anyways I wrote the code using a different method which worked just as well...but I'd still like to know about the proper way to write that and if I didn't understand it correctly if you happen to view this again. Thanks MVeda :)

The code I used is posted below in case anyone else needs help with this...it's code for a module:

Public Function DaysToCompletion() As Long

'Opening tblContracts as recSet1
Dim con1 As ADODB.Connection
Dim recSet1 As ADODB.Recordset
Set con1 = CurrentProject.Connection
Set recSet1 = New ADODB.Recordset
recSet1.Open "tblContracts", con1

'Declaring UntilCompletion as the amount of days until completion
Dim UntilCompletion As Long

'Looping until EOF (until the last record for EndDate in tblContracts...so
'someone else would have declared recSet1.Open
'"tblWhateverYourTableNameIs", con1 which means
'connection1 and then to open a field in that recordset you type
'recSet1.Fields("fieldname"))
Do Until recSet1.EOF
' End Date must be in quotes or will not work
UntilCompletion = DateDiff("d", Date, recSet1.Fields("EndDate"))
Debug.Print UntilCompletion
recSet1.MoveNext
Loop

'Clearing recSet1 and Con1 (Connection1)
recSet1.Close
con1.Close
Set con1 = Nothing
Set recSet1 = Nothing

End Function


Cheers,
Kosmös
Dec 7 '06 #5
MSeda
159 Expert 100+
You are inserting into one field, DateDifference. however you select two fields to insert, tblContracts.EndDate As EndDate AND the result of the iif statement as DateDifference.
It is the "AS dateDifference" that assigns the temporary name to the result of iif.
the part that I suggested you drop, tblContracts.EndDate As EndDate, is assigning the temporary name of EndDate to TblContracts.EndDate, and is not neccessary for the iif statement to function.
Dec 7 '06 #6
NeoPa
32,556 Expert Mod 16PB
Kosmos,

MSeda is right on the button here.
He has perfectly correctly (and quite clearly) answered your original question.
If you read it again carefully you should understand what was wrong with your SQL code.
Dec 8 '06 #7
MMcCarthy
14,534 Expert Mod 8TB
Kosmos

As both NeoPa and MSeda have explained you have been given the answer. To explain it further You cannot do the two actions in the one INSERT statement. You will have to separate them out into two separate queries. Please find below the code as it should be written.

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO tblDateDifference (  DateDifference )
  2. SELECT DaysToCompletion(EndDate)  AS DateDifference
  3. FROM tblContracts
  4. WHERE Date() > tblContracts.EndDate;
  5.  
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO tblDateDifference (  DateDifference )
  2.  SELECT DaysCompleted(EndDate) AS DateDifference
  3.  FROM tblContracts
  4. WHERE Date() <= tblContracts.EndDate;
  5.  
Mary
Dec 9 '06 #8
Kosmos
153 100+
Thanks...yeah I just hadn't understood exactly how things worked...the books availaible for my company were not very helpful in starting off...but I found a very good one recently that allows me to do more module based coding which I prefer more
Dec 15 '06 #9
Kosmos
153 100+
By the way if anyone was following the code I put in to open the form...
you can just do:

Sub openForm()
DoCmd.openForm "frmCustomer"
End Sub

But it's better to open a form the other way because it's just better to practice it that way in case you are opening forms in other databases....this code assumes you are only working in the current database
Dec 15 '06 #10

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

Similar topics

2
by: Robert McEuen | last post by:
Using Access 97, Windows XP I'm receiving a Numeric Field Overflow error during text import that I did not receive before I split my database. Another thread I found suggested that the cause of...
2
by: ralamo | last post by:
When i execute the following insert query, the above mentioned error is coming. Anything wrong in the query? INSERT INTO ECN_1 (Old_SbPartNo, Old_PartDesc, Old_ManPartNo, Old_Manuf,...
3
by: Nathan Bloomfield | last post by:
Hi there, I am having difficulty with a piece of code which would work wonders for my application if only the error trapping worked properly. Basically, it works as follows: - adds records...
3
by: windandwaves | last post by:
Hi Gurus Does anyone know how I set the error trapping to option 2 in visual basic. I know that you can go to tools, options and then choose on unhandled errors only, but is there a VB command...
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
6
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am...
3
by: Shokoth | last post by:
Hi I have been trying to run this code, and what it is doing is inserting records into a table called tblRequestByService. the values that it is inserting are taken from the form itslef (They are...
2
by: cypriot | last post by:
Hi. I am developing an application program in java. I use MsAccess for keeping data. I had a problem with sql insert method. public void AddPatient() { String...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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?
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,...

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.