Hello,
I started working on VBA,access from yesterday, and here I am with my first problem :). Please help.
I get the above mentioned problem when my UDF is returning an integer.(Following is the UDF):
************************************************** - Function Missing(a As String) As Integer
-
Static count_mis As Integer
-
On Error GoTo Err_Trap
-
-
If a = "M" Then
-
count_mis = 1
-
ElseIf a = "I" Then
-
count_mis = 2
-
ElseIf IsNull(a) = True Then
-
count_mis = 3
-
ElseIf IsEmpty(a) = True Then
-
count_mis = 4
-
ElseIf IsError(a) = True Then
-
count_mis = 5
-
Else
-
count_mis = 6
-
End If
-
-
Missing = count_mis
-
-
Exit_Trap:
-
Exit Function
-
Err_Trap:
-
MsgBox Err.Description
-
Missing = 2
-
Resume Exit_Trap
-
End Function
-
************************************************
The argument passed to the UDF is a field which is either I or M or blank. The call to the UDF in the Where clause is:
(Missing([Missing data summary].Field40) = 1)
But I get data mismatch here. Is it beacause of the blank values in Field40,( which show an error in the retrieved table,if I run the query withouth this criteria in where clause). I get a 1 and 2 respectively corresponding to "M" or "I" in the Field40
Thank you!
10 1890
Sorry Forgot to mention,I need only those records to be selected which have a "M" in Field40 of Missing data summary table. I have written this complex logic as I need to further modify it such that the return value from the UDF will be derived from a logic on values of 30 fields in the record including field40. Thanks!!
Try: - (Missing([Missing data summary].Field40)) = 1
The outer parens () are redundant, but might be needed when you expand to 30 fields.
@OldBirdman
@OldBirdman
Thank you so much for the prompt reply. The mismatch is gone but I get an Unknown Jet error now. I do not know what that is,so will get back once i know. Thanks
well, not sure what happened, but without changing much (or anything) I am back to the data mismatch error now. This is after i included the redundant parenthesis :) does this give us any clue?
Not really!
The function should be "Public" and in a Standard Module, not a Class Module.
Can you post the SQL statement?
Yepp it is in standard module and have made it public now. same result though. Here is the SQL query(smaller version,all that is required now and goes down with same error):
SELECT [Missing data summary].Field40
FROM [Missing data summary]
WHERE((Missing([Missing data summary].Field40)) Like 1);
What immediately stands out is that there is no blank after the keyword WHERE
If that is not the problem, open a new query in Design View. Close the "Show Table" window without using it. Click SQL on the query toolbar (leftmost icon). Paste your SQL statement into the textbox
Switch to DataSheet View (leftmost icon).
If it works, the problem is elsewhere in your code.
If it doesn't work, put a BreakPoint in your function "Missing" on the line [If a = "M" Then]. Step through the code to be sure it is working as you expect.
Switch to Design View for the query. This should have your function on the "Criteria:" row of the design grid.
I must leave now for a couple of hours. Good luck!
Hi, Thank you for you reply again. I tried out what you told me,the query does not work either way. I am unable to figure out what is wrong using breakpoints. However I have broken down the problem to the following:
There are 3 possible values of the field to be passed to
the function they are "m", "i" (both as String) and a NUll. The null causes the function to error, and even the trap i have set does not catch the error.
I tried to get around this by using a subquery in the FROM statement to filter out non-Null values only to which the where clause will be applied. If I do not use the Where clause the query works fine, but witht the where clause i again get data mismatch error.
Not sure why, when the values passed is an integer and I have an integer in the criteria condition.Following are the simplified query and code.
code:
Public Function Missing(Optional a As String) As Integer
On Error GoTo Err_Trap
Dim count_mis As Integer
If a = "M" Then
count_mis = 1
ElseIf a = "I" Then
count_mis = 2
Else: IsNull (a)
count_mis = 6
End If
Missing = count_mis
Exit_Trap:
Exit Function
Err_Trap:
MsgBox Err.Description
Missing = 2
Resume Exit_Trap
End Function
Query:
SELECT [Missing data summary].Field40, Missing([Missing data summary].Field40)
FROM (SELECT [Missing data summary].Field40 FROM [Missing data summary] WHERE [Missing data summary].Field40 IS Not Null)
WHERE (Missing([Missing data summary].Field40) = 1);
Thanks!!
Thank you very much. I got this. The Data Mismatch wasnt in the return value passed back to the query but the parameter passed by the query. Just had to accept the parameter in the UDF as a variant data type.
I'm glad you figured it out yourself. Your complete statement of what you tried, and what happened was quite clear. Sometimes a carefully composed question can help solve a problem better than any help a forum can give.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Christian |
last post by:
HI,
I have a function that is used to constrain a query:
Select COl1, Col2
From MyTable
WHERE col1 = ...
AND col2 = ...
And MyFunction(col1) = ...
My problem is that MyFunction is executed...
|
by: joshsackett |
last post by:
I have a WHERE clause that could be an "=" or a "LIKE" depending upon
if the passed variable is populated or not. I would like to know the
best way to write the WHERE clause to make it dynamically...
|
by: msnews.microsoft.com |
last post by:
Hi All,
When I use a SQL Query to Fill the Dataset if I use the following Where
Clause
( > '100' )
Then I am getting a 'Data Type Mismatch Error' because the Field Type is
double.
|
by: Britney |
last post by:
Original code:
this.oleDbSelectCommand1.CommandText = "SELECT TOP 100 user_id, password, nick_name, sex, age, has_picture, city, state, " +
"country FROM dbo.users WHERE (has_picture = ?) AND (sex...
|
by: Zygo Blaxell |
last post by:
I have a table with a few million rows of temperature data keyed
by timestamp. I want to group these rows by timestamp intervals
(e.g. every 32 seconds), compute aggregate functions on the...
|
by: The Other Mike |
last post by:
VS 2005
Is their a way to dynamically change the where clause in a datagridview or
dataset?
I have a search window where the user can enter a part number or description
or customer etc... and...
|
by: Altman |
last post by:
I am playing around with making a dataset with the designer in vb.net
2005. I realize you can add parameters to select statement and then
filter off of those parameters. What I would like to do...
|
by: Jim.Mueksch |
last post by:
I am having a problem with using calculated values in a WHERE clause.
My query is below. DB2 gives me this error message: Error: SQL0206N
"APPRAISAL_LESS_PRICE" is not valid in the context where...
|
by: Gregg K |
last post by:
I'm using Office 2003 on Xp sp2.
Please notice that this VBA code works and produces
a record set which contains the desired data if the WHERE
clause is omitted. When, however, the code is run...
|
by: Yitzak |
last post by:
Hi spent a few hours on this one wrote a query that joined on results
of 2 other queries.
Qry3 using Qry1 and Qry2
When I used Qry1.FasText <cstr(Qry2.FasInteger) in the where clause
- got...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
| |