473,386 Members | 1,766 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.

using functions as criteria in a query

I have created a query in Access 2003 as follows:

Expand|Select|Wrap|Line Numbers
  1. WHERE (((AccDS1check) Is Not Null) AND ((AccFabDate)=GetFDate()) AND ((AccRelacion)=21))
  2.  
AccFabDate is a date value and GetFabDate is a function thus:

Expand|Select|Wrap|Line Numbers
  1. Public Function GetFabDate () As String
  2. GetFabDate = ">#01/01/1980# and < #01/01/2011#”
  3. End Function
  4.  
When I run the query with ((AccFabDate)= ">#01/01/1980# and < #01/01/2011#”) there is no problem but when I use the public function to define the query, Access 2003 either crashes or returns.

Error 3464: mismatch in criteria expression. The criteria expression in a Find method is attempting to compare a field with a value whose data type does not match the field’s data type.

Can anyone help? I need to be able to change the query value dynamically and have code to calculate the string values in the public function
Mar 20 '11 #1

✓ answered by ADezii

I've never seen a Function used in this manner, to return a Criteria String, and I'm not even sure if it will work. What I am sure will work is to:
  1. Pass the Value of your Date Field to a Public Function.
  2. Have the Function return a Boolean Value indicating whether or not the Date Argument is within a specified Range.
  3. As an additional Criteria, return all Records where the Return Value of the Function is True (within Range). It must also, of course, meet any additional Criteria because of the 'ANDs'.
Expand|Select|Wrap|Line Numbers
  1. WHERE ([AccDS1check] Is Not Null) AND ([AccRelacion] = 21)  AND (GetFabDate([AccFabDate]) = True) 
Expand|Select|Wrap|Line Numbers
  1. Public Function GetFabDate(dteDate As Date) As Boolean
  2.   GetFabDate = (dteDate >= #1/1/1980# And dteDate <= #1/1/2011#)
  3. End Function
P.S. - I'm making the Assumptions that [AccFabDate] cannot be NULL, and is a Valid Date.

2 5541
ADezii
8,834 Expert 8TB
I've never seen a Function used in this manner, to return a Criteria String, and I'm not even sure if it will work. What I am sure will work is to:
  1. Pass the Value of your Date Field to a Public Function.
  2. Have the Function return a Boolean Value indicating whether or not the Date Argument is within a specified Range.
  3. As an additional Criteria, return all Records where the Return Value of the Function is True (within Range). It must also, of course, meet any additional Criteria because of the 'ANDs'.
Expand|Select|Wrap|Line Numbers
  1. WHERE ([AccDS1check] Is Not Null) AND ([AccRelacion] = 21)  AND (GetFabDate([AccFabDate]) = True) 
Expand|Select|Wrap|Line Numbers
  1. Public Function GetFabDate(dteDate As Date) As Boolean
  2.   GetFabDate = (dteDate >= #1/1/1980# And dteDate <= #1/1/2011#)
  3. End Function
P.S. - I'm making the Assumptions that [AccFabDate] cannot be NULL, and is a Valid Date.
Mar 20 '11 #2
NeoPa
32,556 Expert Mod 16PB
The function GetFabDate() (or maybe GetFDate() depending on what we look at) returns a value. It is not ever used in your example to formulate the SQL code.

I think you probably want the simpler Between construct :
Expand|Select|Wrap|Line Numbers
  1. WHERE (([AccDS1check] Is Not Null)
  2.   AND  ([AccFabDate] Between #1/1/1980# And #12/31/2010#
  3.   AND  ([AccRelacion]=21))
Mar 20 '11 #3

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

Similar topics

3
by: Mike Ridley | last post by:
I am running Access 97 on a Windows XP system. I run a query on an ODBC connected file that selects records for a particular date. I can hard code the selection criteria eg #25/03/2004# or get it...
2
by: dskillingstad | last post by:
I'm trying to set up a parameter query based on an unbound form. This search form has about 5 text boxes where the user can type in values within each box and search a specific table based on the...
4
by: meganrobertson22 | last post by:
Hi Everyone- I have a question about how to add and then use the "All" selection in a combo box. I am trying to figure out how to: (1) add "All" as a selection to a combo box and then (2)...
1
by: lucazz | last post by:
I have a form with 2 comboboxes (dept, section) and a listbox (employees). Listbox is based on a query with 2 criteria (Forms!Form!Dept and Forms!Form!Section). Whenever I choose values in both...
33
by: Birky | last post by:
Can you please help me understand how to build Criteria syntax within the Query Builder? If you have a field that is for a region (lets say for Midwest) and you have another field which breaks...
2
by: dlajeune | last post by:
I have a VBA script that returns a value (such as "ON" or "BC" or "AB"). I would like to add that value as the criteria in my Access query. The work flow within VBA is Get values from form's...
6
by: vljones | last post by:
I have the following in Db:- tbl_Est - Num_ClaimNo - Date_Date - Num_Estimate I need this query to link to data in another table - tbl_Bord05, in which there is also a...
3
by: tomric | last post by:
I have a query that filters data and places the results in several text boxes on a form. I want to take the numbers in those txtboxes and use them as criteria for a different query. How do you take...
2
by: ziccardi | last post by:
When my query is executed it produces no results. However, if I copy and paste the criteria from the information populated and referenced in my query, it works fine. The criteria needs to be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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
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
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.