I'm attempting to use the DSum function to get the sum of selected records. However, when I try to assign this number to a variable, I get error number 3163: The field is too small to accept the amount of data you attempted to add. Try inserting or pasting less data. I have verified that the query string gets the correct results and that the summed field exists. Here is my code: - Dim lngSelectionTotal As Long
-
Dim strSelected As String
-
-
strSelected = "SELECT tblAnswerLevel.ID, tblAnswerLevel.CrimeID_fk" & _
-
", tblAnswer.Selection, tblQuestion.QValue " & _
-
"FROM tblAnswerLevel INNER JOIN " & _
-
"(tblQuestion INNER JOIN tblAnswer ON tblQuestion.QuestionID = tblAnswer.QuestionID_fk) " & _
-
"ON tblAnswerLevel.ID = tblAnswer.AnswerLevelID_fk " & _
-
"WHERE tblAnswerLevel.ID = " & Me.ID & " AND tblAnswer.Selection = True"
-
-
lngSelectionTotal = DSum("QValue", strSelected)
I checked the data type in the table and it is Long Integer. In this particular case, the DSum() value returned should be 4. Not sure how this is too big. At first I had my variable be an integer and then I changed it to long since it was saying that the field was too small. Didn't change anything. I then tried to just find out what number it was returning in the immediate window by entering - ?DSum("QValue", strSelected)
I got the same error. So this leads me to believe that it has nothing to do with the variable data type having enough room to hold the number returned.
I looked up the error number through MSDN, but it basically said that you will get this error if the number is over 100 characters, which 4 is one hundredth of that. Here is a link to the website: Error 3163. I have never gotten this error before and don't know where to go from here as I don't see my data matching the "cause" of this error according to MSDN.
expression.DSum(Expr, Domain, Criteria)
(...)Domain Required String A string expression identifying the set of records that constitutes the domain. It can be a table name or a query name for a query that does not require a parameter.(...)
You can not use an SQL string at this point. Surprised a debug compile didn't choke on you... although, in this case, it would be looking for a table or query named for the resolved value in the string.
Just another example of MS technically correct and yet totally useless error messages.
4 2589 zmbd 5,501
Expert Mod 4TB
expression.DSum(Expr, Domain, Criteria)
(...)Domain Required String A string expression identifying the set of records that constitutes the domain. It can be a table name or a query name for a query that does not require a parameter.(...)
You can not use an SQL string at this point. Surprised a debug compile didn't choke on you... although, in this case, it would be looking for a table or query named for the resolved value in the string.
Just another example of MS technically correct and yet totally useless error messages.
So basically, I need to take the WHERE clause out of the query and put it in the DSum() function, make my query a querydef, and reference my query in the DSum(). I will try it.
Having tried it, IT WORKS! I ended up having to surround the DSum() function with the Nz() function to handle Nulls.
I wouldn't have guessed that it could ONLY be a table name or query name. I thought that I had used a SQL string in the DLookup() function, but I could be wrong on that. And no, I didn't get a compile error.
Thanks for your help Z.
zmbd 5,501
Expert Mod 4TB
You are correct.
You can use strings in each section of the D*() functions; however, the first string must evaluate to the Name of a Field within the Table/Query referenced in the second section. The string in the second section can be a string; however, it must resolve to the Name of a Table or resolved Query - you can't even use a recordset opened within code unless it has been added to the qrydef. The funny thing, you can use a string in the criteria section of the D*() functions so long as the string evaluates to a valid "WHERE" clause.
NeoPa 32,556
Expert Mod 16PB Seth:
I wouldn't have guessed that it could ONLY be a table name or query name. I thought that I had used a SQL string in the DLookup() function, but I could be wrong on that.
If you check the Help pages you'll find that all Domain Aggregate functions ( D*() ) take only object (Table or QueryDef) names for the Domain parameter. No SQL strings. It does seem a shame, but there it is.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: PA |
last post by:
Hi All,
Thanks for your attention..I appreciate that.
-----Problem description -----------Start----------------------
Database : DB2 UDB 8.2 on Windows 2003
Client: VB6/ADO 2.7 on Windows...
|
by: nagaraj_hayyal |
last post by:
hi all,
i am a c++ developer facing a problem with DB2-CLI on AIX5.2.
we are using db2 v8 fixpak 10, gcc 3.3.2, on aix5.2 with extensive use
of STL vectors.
we are using ODBC 3.0 for our...
|
by: seanseaghan |
last post by:
New to this group, so greetings all!
I am trying to develop query syntax in Access 2000 to accomplish the
following:
Imagine you are in an accounting dept. and you are working on a...
|
by: tommydkat |
last post by:
Hi! I'm updating a Windows application that we develop that uses a DB2
database. We switched from using Microsoft Developer Studio 6 to
Visual Studio .Net 2003 to build our app and since that...
|
by: ckpoll2 |
last post by:
Hi,
I have made a report that has a query as its record source. I put a text box in there that I want to run a dsum function off of a different query. The criteria that I need to use is that it...
|
by: technocraze |
last post by:
Hi community experts,
I am having an isue with Dsum function that is used to count the total number for a particular field (intake) at the textbox afterupdate event with condition/ criteria...
|
by: zaiena |
last post by:
hello,
i'm having this problem when try to display the total amount form subform to form,for example i'm having two tables one for the products which contains(p_no,p_name,price),and the other table...
|
by: JRough |
last post by:
I have a function definition error:
Warning: Missing argument 2 for makexcldata(), called on line 123 and
defined in on line 149
"Warning: mysql_fetch_row(): supplied argument is not a valid...
|
by: wassimdaccache |
last post by:
dears
I have a continuous forms. It contains 2 fields
I made another field to check their accounts. it is .
the source of is based on a DSUM function. "it is working well"
Now I want to...
|
by: Gulnarambi |
last post by:
I have a form in datasheet view with Total and Currency text boxes, in Currency text box I only can enter values of AZN and USD.
Form is based on Table and as criterias information fromUnbound...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |